netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Andrea Claudi <aclaudi@redhat.com>
Cc: netdev@vger.kernel.org, dsahern@gmail.com, markzhang@nvidia.com,
	leonro@nvidia.com
Subject: Re: [PATCH iproute2 1/3] lib/fs: fix memory leak in get_task_name()
Date: Wed, 2 Feb 2022 07:49:53 -0800	[thread overview]
Message-ID: <20220202074953.330c11b2@hermes.local> (raw)
In-Reply-To: <YfqXWG+hyjVtdwR6@tc2>

On Wed, 2 Feb 2022 15:38:16 +0100
Andrea Claudi <aclaudi@redhat.com> wrote:

> On Tue, Feb 01, 2022 at 10:27:12AM -0800, Stephen Hemminger wrote:
> > On Tue,  1 Feb 2022 18:39:24 +0100
> > Andrea Claudi <aclaudi@redhat.com> wrote:
> >   
> > > +	if (fscanf(f, "%ms\n", &comm) != 1) {
> > > +		free(comm);
> > > +		return NULL;  
> > 
> > This is still leaking the original comm.
> >  
> 
> Thanks Stephen, I missed the %m over there :(
> 
> > Why not change it to use a local variable for the path
> > (avoid asprintf) and not reuse comm for both pathname
> > and return value.
> >   
> 
> Thanks for the suggestion. 
> 
> What about taking an extra-step and get rid of the %m too?
> We can do something similar to the get_command_name() function so that
> we don't need to use free in places where we use get_task_name().

What ever works best.

  reply	other threads:[~2022-02-02 15:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01 17:39 [PATCH iproute2 0/3] some memory leak fixes Andrea Claudi
2022-02-01 17:39 ` [PATCH iproute2 1/3] lib/fs: fix memory leak in get_task_name() Andrea Claudi
2022-02-01 18:27   ` Stephen Hemminger
2022-02-02 14:38     ` Andrea Claudi
2022-02-02 15:49       ` Stephen Hemminger [this message]
2022-02-01 17:39 ` [PATCH iproute2 2/3] rdma: stat: fix memory leak in res_counter_line() Andrea Claudi
2022-02-01 17:39 ` [PATCH iproute2 3/3] rdma: RES_PID and RES_KERN_NAME are alternatives to each other Andrea Claudi

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=20220202074953.330c11b2@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=aclaudi@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=leonro@nvidia.com \
    --cc=markzhang@nvidia.com \
    --cc=netdev@vger.kernel.org \
    /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).