All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Hi (Assigning NULL to variable after freeing it).
@ 2018-01-27 12:06 George B
  0 siblings, 0 replies; 3+ messages in thread
From: George B @ 2018-01-27 12:06 UTC (permalink / raw)
  To: linux-kernel

>> I have just started to contribute to linux kernel. I was thinking of
>> giving a patch where a variable is made null after free if not already
>> done.
>>

> General answer is no... unless that particular code expects a freed pointer
> to be null. In many cases the code is written so that this isn't needed,
> so you would have to check each usage on a case-by-case basis.

The answer "no" is overconfidence. Linux kernel should be doing
defensive programming. Not setting the variable to NULL after freeing
it is non-defensive programming.

I know that linux kernel developers think that they are the "best in
the world" but this is not true. There are many better developers
around the world and they do set the variable to NULL after freeing
it.

Even in linux kernel itself, many developers set the variable to NULL
after freeing it. This should become a standard.

But I know that linux kernel developers are obstinate and hence they
will not agree to this.

I hate "many" linux kernel developers because of their arrogance but I
do not hate those linux kernel developers who are not arrogant or
egoist.

Many people believe that setting a variable to NULL after freeing it
is totally justified and should be done. Here is a wikipedia page to
make this case stronger:
https://en.wikipedia.org/wiki/Dangling_pointer

But I know that linux kernel developers are obstinate, arrogant, and
egoists and hence they are not going to agree to this.

George

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Hi (Assigning NULL to variable after freeing it).
  2018-01-17 10:44 Jose Bale
@ 2018-01-17 18:44 ` Randy Dunlap
  0 siblings, 0 replies; 3+ messages in thread
From: Randy Dunlap @ 2018-01-17 18:44 UTC (permalink / raw)
  To: Jose Bale, linux-kernel

On 01/17/18 02:44, Jose Bale wrote:
> Hi All,
> 
> I have just started to contribute to linux kernel. I was thinking of
> giving a patch where a variable is made null after free if not already
> done.
> 
> Some thing like this:
> Original code:
>   kfree(x);
>   ...........some other code...........
> 
> I will change this code to:
> New code:
>   kfree(x);
> ++ x = NULL;
>   ...........some other code...........
> 
> Will this kind of code change be accepted by linux kernel?
> 
> Also, isn't doing this a better practice - that is, assigning NULL to
> variable after freeing it? What is the best practice? What do people
> think about it?
> 
> Any feedback / replies will be greatly appreciated.

General answer is no... unless that particular code expects a freed pointer
to be null.  In many cases the code is written so that this isn't needed,
so you would have to check each usage on a case-by-case basis.

Probably best to find something else to patch.

-- 
~Randy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Hi (Assigning NULL to variable after freeing it).
@ 2018-01-17 10:44 Jose Bale
  2018-01-17 18:44 ` Randy Dunlap
  0 siblings, 1 reply; 3+ messages in thread
From: Jose Bale @ 2018-01-17 10:44 UTC (permalink / raw)
  To: linux-kernel

Hi All,

I have just started to contribute to linux kernel. I was thinking of
giving a patch where a variable is made null after free if not already
done.

Some thing like this:
Original code:
  kfree(x);
  ...........some other code...........

I will change this code to:
New code:
  kfree(x);
++ x = NULL;
  ...........some other code...........

Will this kind of code change be accepted by linux kernel?

Also, isn't doing this a better practice - that is, assigning NULL to
variable after freeing it? What is the best practice? What do people
think about it?

Any feedback / replies will be greatly appreciated.

Regards,
JB

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-27 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-27 12:06 Hi (Assigning NULL to variable after freeing it) George B
  -- strict thread matches above, loose matches on Subject: below --
2018-01-17 10:44 Jose Bale
2018-01-17 18:44 ` Randy Dunlap

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.