De: Antonio Scuri <antonio.sc...@gmail.com>
Enviado: domingo, 17 de maio de 2020 17:23
Para: IUP discussion list.
Assunto: Re: [Iup-users] Repeat of IM's "process/im_analyze.cpp allow 
free(NULL); " patch...

>  For me those "if"s are there also to remind me that those pointers where not 
> allocated. For me one call to >malloc/calloc must match one call to free. 
> Maybe I'm old, but I'll stick with that for now.
Certainly "call to malloc/calloc must match one call to free" is that is 
correct, even if, two free for the same malloc would be double free.

The point is that IF it protects you from double free, only if the pointer is 
marked as NULL, after the free as:
if (ptr) {
   free(ptr);
   ptr = NULL;
}

This is certainly defensive programming and protects the user, but it hides the 
fact that they have a double free bug in the program.

At runtime, it makes no difference, calling free with NULL, as long as the 
pointer has not been released before.
ptr = NULL;
free(ptr);

The big question is how to catch the double free that may exist.

Because this not to protect agaist double free.
if (ptr) {
   free(ptr);
}

regards,
Ranier Vilela


_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to