public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber•org>
To: Andrea Claudi <aclaudi@redhat•com>
Cc: David Ahern <dsahern@kernel•org>,
	netdev@vger•kernel.org, markzhang@nvidia•com, leonro@nvidia•com
Subject: Re: [PATCH iproute2 v2 1/2] lib/fs: fix memory leak in get_task_name()
Date: Mon, 7 Mar 2022 11:57:25 -0800	[thread overview]
Message-ID: <20220307115725.48679a0a@hermes.local> (raw)
In-Reply-To: <YiZNNQB727Il+EVN@tc2>

On Mon, 7 Mar 2022 19:21:41 +0100
Andrea Claudi <aclaudi@redhat•com> wrote:

> On Mon, Mar 07, 2022 at 10:58:37AM -0700, David Ahern wrote:
> > On 3/2/22 5:28 AM, Andrea Claudi wrote:  
> > > diff --git a/include/utils.h b/include/utils.h
> > > index b6c468e9..81294488 100644
> > > --- a/include/utils.h
> > > +++ b/include/utils.h
> > > @@ -307,7 +307,7 @@ char *find_cgroup2_mount(bool do_mount);
> > >  __u64 get_cgroup2_id(const char *path);
> > >  char *get_cgroup2_path(__u64 id, bool full);
> > >  int get_command_name(const char *pid, char *comm, size_t len);
> > > -char *get_task_name(pid_t pid);
> > > +int get_task_name(pid_t pid, char *name);
> > >    
> > 
> > changing to an API with an assumed length is not better than the current
> > situation. Why not just fixup the callers as needed to free the allocation?
> >  
> 
> I actually did that on v1. After Stephen's comment about asprintf(), I
> got the idea to make get_task_name() similar to get_command_name() and
> a bit more "user-friendly", so that callers do not need a free().
> 
> If you think this is not ideal, I can post a v3 with the necessary fixes
> to the callers.
> 
> Thanks,
> Andrea
> 

My comment was purely a suggestion not a requirement.
I have just had issues with complaints from compiler about code not
checking return value from asprintf, so tend to avoid it.

  reply	other threads:[~2022-03-07 19:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02 12:28 [PATCH iproute2 v2 0/2] fix memory leak in get_task_name() Andrea Claudi
2022-03-02 12:28 ` [PATCH iproute2 v2 1/2] lib/fs: " Andrea Claudi
2022-03-03 18:56   ` Leon Romanovsky
2022-03-07 18:07     ` Andrea Claudi
2022-03-07 18:12       ` David Ahern
2022-03-09 13:39       ` Leon Romanovsky
2022-03-07 17:58   ` David Ahern
2022-03-07 18:14     ` Stephen Hemminger
2022-03-07 18:21     ` Andrea Claudi
2022-03-07 19:57       ` Stephen Hemminger [this message]
2022-03-07 22:38       ` David Ahern
2022-03-02 12:28 ` [PATCH iproute2 v2 2/2] rdma: make RES_PID and RES_KERN_NAME alternative 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=20220307115725.48679a0a@hermes.local \
    --to=stephen@networkplumber$(echo .)org \
    --cc=aclaudi@redhat$(echo .)com \
    --cc=dsahern@kernel$(echo .)org \
    --cc=leonro@nvidia$(echo .)com \
    --cc=markzhang@nvidia$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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