diff options
-rw-r--r-- | coreutils/ls.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index c9d24ff4a..9cbb4cab7 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -338,20 +338,18 @@ static struct dnode **dnalloc(int num) | |||
338 | } | 338 | } |
339 | 339 | ||
340 | #ifdef CONFIG_FEATURE_LS_RECURSIVE | 340 | #ifdef CONFIG_FEATURE_LS_RECURSIVE |
341 | static void dfree(struct dnode **dnp) | 341 | static void dfree(struct dnode **dnp, int nfiles) |
342 | { | 342 | { |
343 | struct dnode *cur, *next; | 343 | int i; |
344 | 344 | ||
345 | if (dnp == NULL) | 345 | if (dnp == NULL) |
346 | return; | 346 | return; |
347 | 347 | ||
348 | cur = dnp[0]; | 348 | for (i = 0; i < nfiles; i++) { |
349 | while (cur != NULL) { | 349 | struct dnode *cur = dnp[i]; |
350 | if(cur->allocated) | 350 | if(cur->allocated) |
351 | free(cur->fullname); /* free the filename */ | 351 | free(cur->fullname); /* free the filename */ |
352 | next = cur->next; | ||
353 | free(cur); /* free the dnode */ | 352 | free(cur); /* free the dnode */ |
354 | cur = next; | ||
355 | } | 353 | } |
356 | free(dnp); /* free the array holding the dnode pointers */ | 354 | free(dnp); /* free the array holding the dnode pointers */ |
357 | } | 355 | } |
@@ -561,7 +559,7 @@ static void showdirs(struct dnode **dn, int ndirs, int first) | |||
561 | free(dnd); /* free the array of dnode pointers to the dirs */ | 559 | free(dnd); /* free the array of dnode pointers to the dirs */ |
562 | } | 560 | } |
563 | } | 561 | } |
564 | dfree(subdnp); /* free the dnodes and the fullname mem */ | 562 | dfree(subdnp, nfiles); /* free the dnodes and the fullname mem */ |
565 | #endif | 563 | #endif |
566 | } | 564 | } |
567 | } | 565 | } |
@@ -1151,13 +1149,19 @@ int ls_main(int argc, char **argv) | |||
1151 | shellsort(dnf, dnfiles); | 1149 | shellsort(dnf, dnfiles); |
1152 | #endif | 1150 | #endif |
1153 | showfiles(dnf, dnfiles); | 1151 | showfiles(dnf, dnfiles); |
1152 | if (ENABLE_FEATURE_CLEAN_UP) | ||
1153 | free(dnf); | ||
1154 | } | 1154 | } |
1155 | if (dndirs > 0) { | 1155 | if (dndirs > 0) { |
1156 | #ifdef CONFIG_FEATURE_LS_SORTFILES | 1156 | #ifdef CONFIG_FEATURE_LS_SORTFILES |
1157 | shellsort(dnd, dndirs); | 1157 | shellsort(dnd, dndirs); |
1158 | #endif | 1158 | #endif |
1159 | showdirs(dnd, dndirs, dnfiles == 0); | 1159 | showdirs(dnd, dndirs, dnfiles == 0); |
1160 | if (ENABLE_FEATURE_CLEAN_UP) | ||
1161 | free(dnd); | ||
1160 | } | 1162 | } |
1161 | } | 1163 | } |
1164 | if (ENABLE_FEATURE_CLEAN_UP) | ||
1165 | dfree(dnp, nfiles); | ||
1162 | return (status); | 1166 | return (status); |
1163 | } | 1167 | } |