lkml.org 
[lkml]   [2007]   [Jan]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] [DISCUSS] Make the variable NULL after freeing it.
Date
Ingo Oeser <ioe-lkml@rameria.de> writes:

> Hi,
>
> On Monday, 1. January 2007 07:37, Amit Choudhary wrote:
>> --- Ingo Oeser <ioe-lkml@rameria.de> wrote:
>> > #define kfree_nullify(x) do { \
>> > if (__builtin_constant_p(x)) { \
>> > kfree(x); \
>> > } else { \
>> > typeof(x) *__addr_x = &x; \
>
> Ok, I should change that line to
> typeof(x) *__addr_x = &(x); \
>
>> > kfree(*__addr_x); \
>> > *__addr_x = NULL; \
>> > } \
>> > } while (0)
>> >
>> > Regards
>> >
>> > Ingo Oeser
>> >
>>
>> This is a nice approach but what if someone does kfree_nullify(x+20).
>
> Then this works, because the side effect (+20) is evaluated only once.

It's not a side effect, it's a non-lvalue, and you can't take the address
of a non-lvalue.

Andreas.

--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
-
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-01 17:27    [from the cache]
©2003-2011 Jasper Spaans