From: Yingtai Xie <xieyingtai@huawei.com>
To: christophe.varoqui@opensvc.com, Benjamin Marzinski <bmarzins@redhat.com>
Cc: dm-devel@redhat.com, Joseph Qi <joseph.qi@huawei.com>
Subject: [PATCH] libmultipath: Fix memory leak problem in print_multipath_topology
Date: Mon, 29 Dec 2014 14:44:42 +0800 [thread overview]
Message-ID: <54A0F85A.5020301@huawei.com> (raw)
/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
next reply other threads:[~2014-12-29 6:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-29 6:44 Yingtai Xie [this message]
2015-01-08 22:28 ` [PATCH] libmultipath: Fix memory leak problem in print_multipath_topology Christophe Varoqui
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54A0F85A.5020301@huawei.com \
--to=xieyingtai@huawei.com \
--cc=bmarzins@redhat.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.com \
--cc=joseph.qi@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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 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.