[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240314214640.09463821@hermes.local>
Date: Thu, 14 Mar 2024 21:46:40 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: Ratheesh Kannoth <rkannoth@...vell.com>
Cc: Denis Kirjanov <kirjanov@...il.com>, <dsahern@...nel.org>,
<netdev@...r.kernel.org>, Denis Kirjanov <dkirjanov@...e.de>
Subject: Re: [PATCH iproute2] ifstat: handle strdup return value
On Fri, 15 Mar 2024 07:53:29 +0530
Ratheesh Kannoth <rkannoth@...vell.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.
Powered by blists - more mailing lists