[BusyBox] xfuncts.c xfree() ?

Glenn McGrath bug1 at optushome.com.au
Thu Dec 6 07:39:17 UTC 2001


On Thu, 06 Dec 2001 15:16:32 +0100
"Neal H Walfield" <neal at cs.uml.edu> wrote:

> >> I agree in 'MALLOC_TRACE's free(0) shows up as an error :(
> 
> Why should we ever be calling free with a null pointer unless there
> really is an error?
> 

If there is a variable that may or may not be assigned data (depending
on some condition) then its easier to free it unconditionally rather
than testing it first.

e.g. in unarchival/libunarchive/unarchive.c at the bottom of the file it
does

	free(file_entry->name);
	free(file_entry->link_name);
	free(file_entry);

file_entry->link_name as you can guess will only ever have data if the
file is a sysmlink.

If its wrapped in an if to prevent it from being free'ed if its NULL
i.e.

if (file_entry->link_name) {
	free(file_entry->link_name);
}

then it increases the size of the binary for no functional advantage.



Glenn





More information about the busybox mailing list