libmultipath: Fix memory leak problem in print_multipath_topology
PATCH 1/1 libmultipath: Fix memory leak problem in print_multipath_topology
/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 <[email protected]>
--- libmultipath/print.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
libmultipath/print.c +7 -2
@@ -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);
Signature · 1 line
1.7.12.4
Christophe Varoqui
AppliedApplied,
thanks.
Quoted 53 lines · Yingtai Xie
/sys/block/directory has been opened insnprint_devices, the handler should be released when returned abnormally. Similar memory leak problem happens inprint_multipath_topologywhen carried out multipath -ll command.Signed-off-by Yingtai Xie <[email protected]>--- libmultipath/print.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)libmultipath/print.c +1
-0@@ -890,6 +890,7 @@ print_multipath_topology (struct multipath * mpp, int verbosity) } }while (resize);printf ("%s" , buff); +FREE (buff); }extern int
libmultipath/print.c +3
-1@@ -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/");libmultipath/print.c +3
-1@@ -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