[BusyBox] 14 bugs on the wall/memory leak
Vladimir N. Oleynik
dzo at simtreas.ru
Sun Apr 22 09:09:05 UTC 2001
Larry and Glenn,
> Cuts the number of strlen() operations per file from 4 to 1.
> Better performance, and saves 47 bytes of text size, since
> strcpy is inlined (at least in my build environment).
> Add paranoia check to avoid buffer underrun. By my count,
> the original 14 (potential) bugs on the wall are down to 10.
I long see this and not found potential bug :-0
See new last patch, i think - this best.
Also, special for Glenn - new remove memory leaks.
--w
vodz
-------------- next part --------------
diff -ru busybox.orig/ls.c busybox/ls.c
--- busybox.orig/ls.c Sun Apr 22 12:44:56 2001
+++ busybox/ls.c Sun Apr 22 12:55:36 2001
@@ -547,12 +547,7 @@
if ((strcmp(entry->d_name, "..")==0) && !(disp_opts & DISP_DOT)) continue;
if ((entry->d_name[0] == '.') && !(disp_opts & DISP_HIDDEN)) continue;
cur= (struct dnode *)xmalloc(sizeof(struct dnode));
- cur->fullname = xmalloc(strlen(path)+1+strlen(entry->d_name)+1);
- strcpy(cur->fullname, path);
- if (cur->fullname[strlen(cur->fullname)-1] != '/')
- strcat(cur->fullname, "/");
- cur->name= cur->fullname + strlen(cur->fullname);
- strcat(cur->fullname, entry->d_name);
+ cur->fullname = concat_path_file(path, entry->d_name);
if (my_stat(cur))
continue;
cur->next= dn;
diff -ru busybox.orig/untar.c busybox/untar.c
--- busybox.orig/untar.c Sun Apr 22 12:40:08 2001
+++ busybox/untar.c Sun Apr 22 13:02:23 2001
@@ -143,17 +143,18 @@
char *full_name;
if (file_prefix != NULL) {
- char *file_name = NULL, *file_extension = NULL;
+ char *file_name, *file_extension;
- file_extension = xmalloc(strlen(raw_tar_header.name) + 1);
file_extension = strrchr(raw_tar_header.name, '/');
file_extension++;
file_name = xmalloc(strlen(file_prefix) + strlen(file_extension) + 2);
strcpy(file_name, file_prefix);
strcat(file_name, ".");
strcat(file_name, file_extension);
-
- full_name = concat_path_file(xstrndup(dir, strlen(dir) - strlen(strrchr(dir, '/'))), file_name);
+ file_extension = xstrndup(dir, strlen(dir) - strlen(strrchr(dir, '/')));
+ full_name = concat_path_file(file_extension, file_name);
+ free(file_extension);
+ free(file_name);
} else {
full_name = xstrdup(dir);
}
More information about the busybox
mailing list