svn commit: branches/busybox_1_1_stable/coreutils
aldot at busybox.net
aldot at busybox.net
Fri May 19 10:15:48 UTC 2006
Author: aldot
Date: 2006-05-19 03:15:47 -0700 (Fri, 19 May 2006)
New Revision: 15110
Log:
Patch from Shaun Jackman:
ls has an ugly bug. ls uses an array of pointers, the elements of
which are all in a linked list. To free the elements, instead of
freeing all the elements in the array, array[0..nelements], it frees
by iterating the linked list starting at array[0], which it assumes is
the head of the list. Unfortunately, ls also sorts the array! So,
array[0] is no longer the head, but somewhere in the middle of the
linked list. This patch fixes this bug, and also adds an
ENABLE_FEATURE_CLEAN_UP stanza.
(r14978 from trunk)
Modified:
branches/busybox_1_1_stable/coreutils/ls.c
Changeset:
Modified: branches/busybox_1_1_stable/coreutils/ls.c
===================================================================
--- branches/busybox_1_1_stable/coreutils/ls.c 2006-05-19 10:13:09 UTC (rev 15109)
+++ branches/busybox_1_1_stable/coreutils/ls.c 2006-05-19 10:15:47 UTC (rev 15110)
@@ -350,20 +350,18 @@
}
#ifdef CONFIG_FEATURE_LS_RECURSIVE
-static void dfree(struct dnode **dnp)
+static void dfree(struct dnode **dnp, int nfiles)
{
- struct dnode *cur, *next;
+ int i;
if (dnp == NULL)
return;
- cur = dnp[0];
- while (cur != NULL) {
+ for (i = 0; i < nfiles; i++) {
+ struct dnode *cur = dnp[i];
if(cur->allocated)
free(cur->fullname); /* free the filename */
- next = cur->next;
free(cur); /* free the dnode */
- cur = next;
}
free(dnp); /* free the array holding the dnode pointers */
}
@@ -573,7 +571,7 @@
free(dnd); /* free the array of dnode pointers to the dirs */
}
}
- dfree(subdnp); /* free the dnodes and the fullname mem */
+ dfree(subdnp, nfiles); /* free the dnodes and the fullname mem */
#endif
}
}
@@ -1164,13 +1162,19 @@
shellsort(dnf, dnfiles);
#endif
showfiles(dnf, dnfiles);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(dnf);
}
if (dndirs > 0) {
#ifdef CONFIG_FEATURE_LS_SORTFILES
shellsort(dnd, dndirs);
#endif
showdirs(dnd, dndirs, dnfiles == 0);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(dnd);
}
}
+ if (ENABLE_FEATURE_CLEAN_UP)
+ dfree(dnp, nfiles);
return (status);
}
More information about the busybox-cvs
mailing list