lkml.org 
[lkml]   [2007]   [Jan]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] include/linux/slab.h: new KFREE() macro.

--- Valdis.Kletnieks@vt.edu wrote:
> On Mon, 08 Jan 2007 01:06:12 PST, Amit Choudhary said:
> > I do not see how a double free can result in _logical_wrong_behaviour_ of the program and the
> > program keeps on running (like an incoming packet being dropped because of double free).
> Double
> > free will _only_and_only_ result in system crash that can be solved by setting 'x' to NULL.
>
> The problem is that very rarely is there a second free() with no intervening
> use - what actually *happens* usually is:
>
> 1) You alloc the memory
> 2) You use the memory
> 3) You take a reference on the memory, so you know where it is.
> 4) You free the memory
> 5) You use the memory via the reference you took in (3)
> 6) You free it again - at which point you finally know for sure that
> everything in step 5 was doing a fandango on core....
>

Correct. And doing kfree(x); x=NULL; is not hiding that. These issues can still be debugged by
using the slab debugging options. One other benefit of doing this is that if someone tries to
access the same memory again using the variable 'x', then he will get an immediate crash. And the
problem can be solved immediately, without using the slab debugging options. I do not yet
understand how doing this hides the bugs, obfuscates the code, etc. because I haven't seen an
example yet, but only blanket statements.

But now I know better, since I haven't heard anything in support of this case, I have concluded
that doing kfree(x); x=NULL; is _not_needed_ in the "linux kernel". I hope that no one does it in
the future. And since people vehemently opposed this, I think its better to add another item on
the kernel janitor's list to remove all the (x=NULL) statements where people are doing "kfree(x);
x=NULL".

-Amit


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2007-01-09 20:37    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site