All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Ratheesh Kannoth <rkannoth@marvell.com>
Cc: Denis Kirjanov <kirjanov@gmail.com>, <dsahern@kernel.org>,
	<netdev@vger.kernel.org>, Denis Kirjanov <dkirjanov@suse.de>
Subject: Re: [PATCH iproute2] ifstat: handle strdup return value
Date: Thu, 14 Mar 2024 21:46:40 -0700	[thread overview]
Message-ID: <20240314214640.09463821@hermes.local> (raw)
In-Reply-To: <20240315022329.GA1295449@maili.marvell.com>

On Fri, 15 Mar 2024 07:53:29 +0530
Ratheesh Kannoth <rkannoth@marvell.com> wrote:

> > diff --git a/misc/ifstat.c b/misc/ifstat.c
> > index 685e66c9..f94b11bc 100644
> > --- a/misc/ifstat.c
> > +++ b/misc/ifstat.c
> > @@ -140,6 +140,11 @@ static int get_nlmsg_extended(struct nlmsghdr *m, void *arg)
> >
> >  	n->ifindex = ifsm->ifindex;
> >  	n->name = strdup(ll_index_to_name(ifsm->ifindex));
> > +	if (!n->name) {
> > +		free(n);
> > +		errno = ENOMEM;  
> strdup() will set the errno right ? why do you need to set it explicitly ?
> > +		return -1;

Man page for strdup says:

RETURN VALUE
       On success, the strdup() function returns a pointer to  the  duplicated
       string.  It returns NULL if insufficient memory was available, with er‐
       rno set to indicate the error.


      parent reply	other threads:[~2024-03-15  4:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14 12:20 [PATCH iproute2] ifstat: handle strdup return value Denis Kirjanov
2024-03-15  2:23 ` Ratheesh Kannoth
2024-03-15  2:34   ` David Ahern
2024-03-15  4:46   ` Stephen Hemminger [this message]

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=20240314214640.09463821@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=dkirjanov@suse.de \
    --cc=dsahern@kernel.org \
    --cc=kirjanov@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=rkannoth@marvell.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 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.