diff mbox series

[ndctl,1/5] ndctl, inject: fix a resource leak in ndctl_namespace_get_clear_unit

Message ID 20180810225624.32383-2-vishal.l.verma@intel.com (mailing list archive)
State New, archived
Headers show
Series ndctl: misc static analysis fixes | expand

Commit Message

Verma, Vishal L Aug. 10, 2018, 10:56 p.m. UTC
Static analysis reports that we leak ndctl_cmd in the above function.
Fix by adding a proper cleanup path.

Fixes: 7271760ce96c ("libndctl, inject: inject fewer bytes per block by default")
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/lib/inject.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index f9da02d..268c5cd 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -102,18 +102,20 @@  static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns)
 		&ns_size);
 	cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
 	rc = ndctl_cmd_submit(cmd);
-	if (rc) {
+	if (rc < 0) {
 		dbg(ctx, "Error submitting ars_cap: %d\n", rc);
-		return rc;
+		goto out;
 	}
 	clear_unit = ndctl_cmd_ars_cap_get_clear_unit(cmd);
 	if (clear_unit == 0) {
 		dbg(ctx, "Got an invalid clear_err_unit from ars_cap\n");
-		return -EINVAL;
+		rc = -EINVAL;
+		goto out;
 	}
-
+	rc = clear_unit;
+out:
 	ndctl_cmd_unref(cmd);
-	return clear_unit;
+	return rc;
 }
 
 static int ndctl_namespace_inject_one_error(struct ndctl_namespace *ndns,