git: 0ac468c7b641 - main - nvmecontrol: Free array of I/O queue pairs on failure to handoff

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 10 May 2024 16:41:41 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=0ac468c7b641a1db4ad1435cb7072919ab569c50

commit 0ac468c7b641a1db4ad1435cb7072919ab569c50
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-05-10 16:04:51 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-05-10 16:13:21 +0000

    nvmecontrol: Free array of I/O queue pairs on failure to handoff
    
    This is harmless but cleaner.
    
    Reported by:    Coverity Scan
    CID:            1545041,1545049
    Sponsored by:   Chelsio Communications
---
 sbin/nvmecontrol/connect.c   | 5 ++++-
 sbin/nvmecontrol/reconnect.c | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/sbin/nvmecontrol/connect.c b/sbin/nvmecontrol/connect.c
index afb78725a3c7..14bd0cce1f8f 100644
--- a/sbin/nvmecontrol/connect.c
+++ b/sbin/nvmecontrol/connect.c
@@ -84,12 +84,15 @@ connect_nvm_controller(enum nvmf_trtype trtype, int adrfam, const char *address,
 	error = connect_nvm_queues(&aparams, trtype, adrfam, address, port,
 	    cntlid, subnqn, opt.hostnqn, opt.kato, &admin, io,
 	    opt.num_io_queues, opt.queue_size, &cdata);
-	if (error != 0)
+	if (error != 0) {
+		free(io);
 		return (error);
+	}
 
 	error = nvmf_handoff_host(admin, opt.num_io_queues, io, &cdata);
 	if (error != 0) {
 		warnc(error, "Failed to handoff queues to kernel");
+		free(io);
 		return (EX_IOERR);
 	}
 	free(io);
diff --git a/sbin/nvmecontrol/reconnect.c b/sbin/nvmecontrol/reconnect.c
index c8a010c038d0..b606409eea90 100644
--- a/sbin/nvmecontrol/reconnect.c
+++ b/sbin/nvmecontrol/reconnect.c
@@ -85,12 +85,15 @@ reconnect_nvm_controller(int fd, enum nvmf_trtype trtype, int adrfam,
 	error = connect_nvm_queues(&aparams, trtype, adrfam, address, port,
 	    rparams.cntlid, rparams.subnqn, opt.hostnqn, opt.kato, &admin, io,
 	    opt.num_io_queues, opt.queue_size, &cdata);
-	if (error != 0)
+	if (error != 0) {
+		free(io);
 		return (error);
+	}
 
 	error = nvmf_reconnect_host(fd, admin, opt.num_io_queues, io, &cdata);
 	if (error != 0) {
 		warnc(error, "Failed to handoff queues to kernel");
+		free(io);
 		return (EX_IOERR);
 	}
 	free(io);