All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libmultipath: Fix memory leak problem in print_multipath_topology
@ 2014-12-29  6:44 Yingtai Xie
  2015-01-08 22:28 ` Christophe Varoqui
  0 siblings, 1 reply; 2+ messages in thread
From: Yingtai Xie @ 2014-12-29  6:44 UTC (permalink / raw)
  To: christophe.varoqui, Benjamin Marzinski; +Cc: dm-devel, Joseph Qi

/sys/block/ directory has been opened in snprint_devices, the handler
should be released when returned abnormally. Similar memory leak problem
happens in print_multipath_topology when carried out multipath -ll command.

Signed-off-by: Yingtai Xie <xieyingtai@huawei.com>
---
 libmultipath/print.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libmultipath/print.c b/libmultipath/print.c
index 383eae4..916906f 100644
--- a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -890,6 +890,7 @@ print_multipath_topology (struct multipath * mpp, int verbosity)
 		}
 	} while (resize);
 	printf("%s", buff);
+	FREE(buff);
 }

 extern int
@@ -1427,8 +1428,10 @@ snprint_devices (char * buff, int len, struct vectors *vecs)
 	if (!(blkdir = opendir("/sys/block")))
 		return 1;

-	if ((len - fwd - threshold) <= 0)
+	if ((len - fwd - threshold) <= 0) {
+		closedir(blkdir);
 		return len;
+	}
 	fwd += snprintf(buff + fwd, len - fwd, "available block devices:\n");

 	strcpy(devpath,"/sys/block/");
@@ -1446,8 +1449,10 @@ snprint_devices (char * buff, int len, struct vectors *vecs)
 		if (S_ISDIR(statbuf.st_mode) == 0)
 			continue;

-		if ((len - fwd - threshold)  <= 0)
+		if ((len - fwd - threshold)  <= 0) {
+			closedir(blkdir);
 			return len;
+		}

 		fwd += snprintf(buff + fwd, len - fwd, "    %s", devptr);
 		pp = find_path_by_dev(vecs->pathvec, devptr);
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-08 22:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-29  6:44 [PATCH] libmultipath: Fix memory leak problem in print_multipath_topology Yingtai Xie
2015-01-08 22:28 ` Christophe Varoqui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.