[Xastir-Dev] "Reindex ALL Maps" SIG-11 fix

Henk de Groot henk.de.groot at hetnet.nl
Mon Aug 18 13:17:31 EDT 2003


At 14:59 17-8-03 -0400, Derrick J Brashear wrote:

>Won't this leak the first string to be freed?
>Isn't the correct answer to instead free temp->XmStringPtr?

No, thats just another solution. If "current = current->next;" is moved 
after the "if (current....) {" then "temp" and "current" contain the same 
adress.
So temp->XmStringPtr and current->XmStringPtr free to the same allocated data.

Instead of moving "current = current->next;" one could also replace 
"current" with "temp" to fix the problem. I chose to use "temp" only to 
save the address when current is advanced to current->next. If I whould 
have written the code I would also move the assignment "temp = current;" to 
the end so you get one block:

         temp = current;
         current = current->next;
         free(temp);

This way you can see very clear these belong together and "temp" is realy 
only used to retain the address for a very short time. If the function is 
bigger there is always a risk somebody uses "temp" for some other purpose 
between assignment and use; by puting it on subsequent lines nothing can 
get inbetween.

Kind regards,

Henk.



More information about the Xastir-dev mailing list