All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@lists.linux.dev>,
	Martin Wilck <Martin.Wilck@suse.com>
Subject: Re: [PATCH] libmultipath/foreign: fix memory leak in nvme foreign handler
Date: Wed, 8 Jan 2025 19:26:54 -0500	[thread overview]
Message-ID: <Z38XzlEsDLchkUIi@redhat.com> (raw)
In-Reply-To: <20250109000653.2469651-1-bmarzins@redhat.com>

On Wed, Jan 08, 2025 at 07:06:53PM -0500, Benjamin Marzinski wrote:
> _find_controllers() needs to free the udev device if it doesn't get
> added to a path. Otherwise it can leak memory whenever check_foreign()
> is called, causing multipathd's memory usage to continually grow.
> 

This also belongs in the stable branch.

-Ben

> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  libmultipath/foreign/nvme.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c
> index 0b7f4eab..cde660ce 100644
> --- a/libmultipath/foreign/nvme.c
> +++ b/libmultipath/foreign/nvme.c
> @@ -675,7 +675,8 @@ static void _find_controllers(struct context *ctx, struct nvme_map *map)
>  	pthread_cleanup_push_cast(free_scandir_result, &sr);
>  	for (i = 0; i < r; i++) {
>  		char *fn = di[i]->d_name;
> -		struct udev_device *ctrl, *udev;
> +		struct udev_device *ctrl;
> +		struct udev_device *udev __attribute__((cleanup(cleanup_udev_device))) = NULL;
>  
>  		if (safe_snprintf(pathbuf + n, sizeof(pathbuf) - n, "/%s", fn))
>  			continue;
> @@ -719,11 +720,11 @@ static void _find_controllers(struct context *ctx, struct nvme_map *map)
>  			continue;
>  
>  		path->gen.ops = &nvme_path_ops;
> -		path->udev = udev;
> +		path->udev = steal_ptr(udev);
>  		path->seen = true;
>  		path->map = map;
>  		path->ctl = udev_device_get_parent_with_subsystem_devtype
> -			(udev, "nvme", NULL);
> +			(path->udev, "nvme", NULL);
>  		if (path->ctl == NULL) {
>  			condlog(1, "%s: %s: failed to get controller for %s",
>  				__func__, THIS, fn);
> @@ -744,7 +745,7 @@ static void _find_controllers(struct context *ctx, struct nvme_map *map)
>  		}
>  		vector_set_slot(&map->pgvec, &path->pg);
>  		condlog(3, "%s: %s: new path %s added to %s",
> -			__func__, THIS, udev_device_get_sysname(udev),
> +			__func__, THIS, udev_device_get_sysname(path->udev),
>  			udev_device_get_sysname(map->udev));
>  	}
>  	pthread_cleanup_pop(1);
> -- 
> 2.46.2
> 


  reply	other threads:[~2025-01-09  0:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-09  0:06 [PATCH] libmultipath/foreign: fix memory leak in nvme foreign handler Benjamin Marzinski
2025-01-09  0:26 ` Benjamin Marzinski [this message]
2025-01-14 21:45 ` Martin Wilck

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=Z38XzlEsDLchkUIi@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=Martin.Wilck@suse.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    /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.