[BusyBox] xfuncts.c xfree() ?

Neal H Walfield neal at cs.uml.edu
Fri Dec 7 02:51:53 UTC 2001


> Yes, youve correctly pointed out some problems with that code, and i
> will try and reorganise unarchive.c today.
>
> My code asside im sure there are cases where being able to free(NULL) is
> usefull.

Yours was only the first piece of code that I looked at.  After the
email, I browsed through the other references that you gave me and
searched for other code that also frees pointers unconditionally: in
all of the cases that I looked at, it was wrong or, in the very least,
could have been coded better and thereby avoided this situation to
begin with.  For instance in deb_extract, there is no reason that
ared_file should be a copy of a constant string.  Just point it to the
string and be done with it.  I.e.

--- busybox-0.60.2.orig/libbb/unarchive.c       Sat Oct 27 01:08:06 2001
+++ busybox-0.60.2/libbb/unarchive.c    Thu Dec  6 16:12:21 2001
@@ -578,10 +578,10 @@ char *deb_extract(const char *package_fi
        }
        
        if (extract_function & extract_control_tar_gz) {
-               ared_file = xstrdup("control.tar.gz");
+               ared_file = "control.tar.gz";
        }
        else if (extract_function & extract_data_tar_gz) {              
-               ared_file = xstrdup("data.tar.gz");
+               ared_file = "data.tar.gz";
        }
 
        /* open the debian package to be worked on */
@@ -611,7 +611,6 @@ char *deb_extract(const char *package_fi
        gz_close(gunzip_pid);
        fclose(deb_stream);
        fclose(uncompressed_stream);
-       free(ared_file);
        return(output_buffer);
 }
 #endif






More information about the busybox mailing list