[dm-devel] [PATCH] libmultipath: Fix memory leak problem in print_multipath_topology

Christophe Varoqui christophe.varoqui at opensvc.com
Thu Jan 8 22:28:12 UTC 2015


Applied,
thanks.

On Mon, Dec 29, 2014 at 7:44 AM, Yingtai Xie <xieyingtai at huawei.com> 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 at 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 part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/dm-devel/attachments/20150108/65ccccd0/attachment.htm>


More information about the dm-devel mailing list