Re: [PATCH] libmultipath: Fix memory leak problem in print_multipath_topology

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Applied,
thanks.

On Mon, Dec 29, 2014 at 7:44 AM, Yingtai Xie <xieyingtai@xxxxxxxxxx> wrote:
/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@xxxxxxxxxx>
---
 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


--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel

[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux