diff mbox series

[ndctl,3/5] libndctl: fix a resource leak in ndctl_dimm_get_{{event_}flags, health}

Message ID 20180810225624.32383-4-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 functions.
Fix by adding proper cleanup paths.

Cc: QI Fuli <qi.fuli@jp.fujitsu.com>
Fixes: fdf6b6844ccf ("ndctl, monitor: add a new command - monitor")
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/lib/libndctl.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ab47b27..226a577 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1649,6 +1649,7 @@  NDCTL_EXPORT unsigned int ndctl_dimm_get_health(struct ndctl_dimm *dimm)
 	}
 	if (ndctl_cmd_submit(cmd)) {
 		err(ctx, "%s: smart command failed\n", devname);
+		ndctl_cmd_unref(cmd);
 		return UINT_MAX;
 	}
 
@@ -1671,6 +1672,7 @@  NDCTL_EXPORT unsigned int ndctl_dimm_get_flags(struct ndctl_dimm *dimm)
 	}
 	if (ndctl_cmd_submit(cmd)) {
 		dbg(ctx, "%s: smart command failed\n", devname);
+		ndctl_cmd_unref(cmd);
 		return UINT_MAX;
 	}
 
@@ -1700,6 +1702,7 @@  NDCTL_EXPORT unsigned int ndctl_dimm_get_event_flags(struct ndctl_dimm *dimm)
 	}
 	if (ndctl_cmd_submit(cmd)) {
 		err(ctx, "%s: smart command failed\n", devname);
+		ndctl_cmd_unref(cmd);
 		return UINT_MAX;
 	}