nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 1/5] ndctl, inject: fix a resource leak in ndctl_namespace_get_clear_unit
Date: Fri, 10 Aug 2018 16:56:20 -0600	[thread overview]
Message-ID: <20180810225624.32383-2-vishal.l.verma@intel.com> (raw)
In-Reply-To: <20180810225624.32383-1-vishal.l.verma@intel.com>

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 --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)
 	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;
-	return clear_unit;
+	return rc;
 static int ndctl_namespace_inject_one_error(struct ndctl_namespace *ndns,

Linux-nvdimm mailing list

  reply	other threads:[~2018-08-10 22:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 22:56 [ndctl PATCH 0/5] ndctl: misc static analysis fixes Vishal Verma
2018-08-10 22:56 ` Vishal Verma [this message]
2018-08-10 22:56 ` [ndctl PATCH 2/5] ndctl: fix a resource leak in submit_get_firmware_info Vishal Verma
2018-08-10 22:56 ` [ndctl PATCH 3/5] libndctl: fix a resource leak in ndctl_dimm_get_{{event_}flags, health} Vishal Verma
2018-08-10 22:56 ` [ndctl PATCH 4/5] ndctl, test: fix a potential null pointer dereference in 'ndctl test' Vishal Verma
2018-08-10 22:56 ` [ndctl PATCH 5/5] ndctl, test: fix a resource leak in check_smart_threshold Vishal Verma
2018-08-10 22:58 ` [ndctl PATCH 0/5] ndctl: misc static analysis fixes Dave Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180810225624.32383-2-vishal.l.verma@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=linux-nvdimm@lists.01.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).