[PATCH 01/11] xfsprogs: xfs_io: fix a memory leak in imap_f
Vivek Trivedi
t.vivek at samsung.com
Wed Dec 2 05:19:17 CST 2015
add NULL check for malloc return and free allocated memory in
return path in imap_f
Signed-off-by: Vivek Trivedi <t.vivek at samsung.com>
---
io/imap.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/io/imap.c b/io/imap.c
index 34901cb..6ed98eb 100644
--- a/io/imap.c
+++ b/io/imap.c
@@ -39,6 +39,8 @@ imap_f(int argc, char **argv)
nent = atoi(argv[1]);
t = malloc(nent * sizeof(*t));
+ if (!t)
+ return 0;
bulkreq.lastip = &last;
bulkreq.icount = nent;
@@ -46,8 +48,10 @@ imap_f(int argc, char **argv)
bulkreq.ocount = &count;
while (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, &bulkreq) == 0) {
- if (count == 0)
+ if (count == 0) {
+ free(t);
return 0;
+ }
for (i = 0; i < count; i++) {
printf(_("ino %10llu count %2d mask %016llx\n"),
(unsigned long long)t[i].xi_startino,
@@ -55,6 +59,7 @@ imap_f(int argc, char **argv)
(unsigned long long)t[i].xi_allocmask);
}
}
+ free(t);
perror("xfsctl(XFS_IOC_FSINUMBERS)");
exitcode = 1;
return 0;
--
1.7.9.5
More information about the xfs
mailing list