dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: lixiaokeng <lixiaokeng@huawei.com>,
	Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	dm-devel mailing list <dm-devel@redhat.com>
Cc: linfeilong <linfeilong@huawei.com>,
	"liuzhiqiang \(I\)" <liuzhiqiang26@huawei.com>
Subject: Re: [dm-devel] [PATCH] libmultipath: fix memory leaks in coalesce_paths
Date: Fri, 16 Oct 2020 21:51:04 +0200	[thread overview]
Message-ID: <757aa2249e036cf2c659bedd6c9fe748af3c0894.camel@suse.com> (raw)
In-Reply-To: <6169bcfa-343d-adc8-a458-5e5c46aed737@huawei.com>

On Fri, 2020-10-16 at 14:23 +0800, lixiaokeng wrote:
> When multipath -F are executed firstly and multipath -v2 or
> -d are executed later, asan will warn memory leaks. The
> reason is that the mpp allocated in coalesce_paths isn't
> freed. Here we add newmp in configure(multipath) to store
> mpp and free it.
> 
> Signed-off-by: Lixiaokeng <lixiaokeng@huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Signed-off-by: Linfeilong <linfeilong@huawei.com>

Besides what Ben noted already, I think you shouldn't force callers to
pass a non-NULL "newmp". The tricky part is to make sure that paths
aren't handled repeatedly in the CMD_DRY_RUN case. Currently pp->mpp !=
NULL is the condition used by coalesce_paths() to check if a path has
already been dealt with; if you simply call remove_map(), that won't
work any more. I suppose you realized that, and that's why you
introduced the non-NULL newmp in multipath (you should have mentioned
that in the changelog message).

I suggest to have callers pass a "vector *pnewmp" instead of "vector
newmp", always allocate newmp in coalesce_paths(), and upon return,
either free newmp, or assign it to the pointer passed by the caller:

     if (pnewmp)
	    *pnewmp = newmp;
     else
            free_multipathvec(newmp, KEEP_PATHS);

Regards,
Martin


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


  parent reply	other threads:[~2020-10-16 19:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16  6:23 [dm-devel] [PATCH] libmultipath: fix memory leaks in coalesce_paths lixiaokeng
2020-10-16 17:31 ` Benjamin Marzinski
2020-10-16 19:51 ` Martin Wilck [this message]
2020-10-19 10:17   ` lixiaokeng

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=757aa2249e036cf2c659bedd6c9fe748af3c0894.camel@suse.com \
    --to=mwilck@suse.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    --cc=linfeilong@huawei.com \
    --cc=liuzhiqiang26@huawei.com \
    --cc=lixiaokeng@huawei.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).