[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAOM0=dbuPP1j7MYkZCxbXQKxUsjeO0QXfE_g-xapFXYSpCAgXw@mail.gmail.com>
Date: Sat, 12 Nov 2022 17:28:04 +0530
From: A <amit234234234234@...il.com>
To: Willy Tarreau <w@....eu>
Cc: linux-kernel@...r.kernel.org
Subject: Re: Setting variable NULL after freeing it.
On Sat, Nov 12, 2022 at 5:04 PM Willy Tarreau <w@....eu> wrote:
>
> On Sat, Nov 12, 2022 at 04:18:37PM +0530, A wrote:
> > >
> > > It depends. What's important is not to let a pointer exist to a freed
> > > location, so if you're doing:
> > >
> > > kfree(card->pool);
> > >
> > > then it's usually important to follow this by:
> > >
> > > card->pool = NULL;
> > >
> >
> > I checked in kernel but at many places this is not being done. I can
> > change all that code. But, will the patch be accepted?
> >
> > So, if someone is doing -
> >
> > kfree(x)
> > ._some_code_
> > ._some_code_
> > ._some_code_
> >
> > Then I can change it to -
> >
> > kfree(x)
> > x = NULL;
> > ._some_code_
> > ._some_code_
> > ._some_code_
> >
> > But, will the patch be accepted for this change?
>
> I don't think so, for the reasons I explained previously,
> unless you spot real bugs there during your reviews, of
> course. Better focus on your own driver for now in my
> opinion.
>
I was just thinking that when this is good practice (where its usage
is genuine), then why is there not a kernel wide macro that would call
kfree(x) and then set (x) = NULL. So, this will be done automatically
for everyone and the developer will not have to decide whether to do
this or not.
Amit
Powered by blists - more mailing lists