Re: [PATCH] [DISCUSS] Make the variable NULL after freeing it.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Ingo Oeser
Date: Monday, January 1, 2007 - 9:09 am

Hi,

On Monday, 1. January 2007 07:37, Amit Choudhary wrote:

Ok, I should change that line to 
		typeof(x) *__addr_x = &(x); \


Then this works, because the side effect (+20) is evaluated only once. 
AFAIK __builtin_constant_p() and typeof() are both free of side effects.

 

kfree_nullify() has to replace kfree() to be of any use one day. So this is not an option.

Anybody thinking of "Hey, this must be NULL afterwards!", will set it to NULL himself.
Anybody else doesn't know or care about it, which is the case we like to catch.


The problems I see are:
1. parameter to kfree is a value not a pointer 
    -> solved by using a macro instead of function, 
         but generate new (the other) problems
    -> take the address of the value there.
2. possible side effects of macro parameter usage 
   -> solved by assigning once only and using typeof
3. Constants don't have an address 
   -> need to check for constant

So apart from missing braces before taking the address, I don't see
any problem with my solution :-)

Should I send a patch?


I reviewed it and you missed side effects (kfree(x); x = NULL).

Regards

Ingo Oeser
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 4/7] work_on_cpu: use in drivers/pci/pci-driver.c, Rusty Russell, (Wed Dec 31, 5:00 pm)
Re: [PATCH] [DISCUSS] Make the variable NULL after freeing it., Ingo Oeser, (Mon Jan 1, 9:09 am)