[PATCH] ls: clean up memory leak
Shaun Jackman
sjackman at gmail.com
Tue May 2 15:16:54 UTC 2006
On 5/1/06, Rob Landley <rob at landley.net> wrote:
> If it's from Vladimir I'd like to confirm that it's under the GPL, since he's
> explicitly stated that some of his previous patches were not GPL.
>
> And I'm not against UTF-8 support, I'd just like it to be done cleanly, and
> the CONFIG option would need to go in before stuff using that CONFIG option.
Hello Rob,
Please apply my original patch, which is free of the UTF-8 blob, fixes
the memory leak with which I was originally concerned, and is a clean
patch.
Cheers,
Shaun
2006-04-21 Shaun Jackman <sjackman at gmail.com>
* coreutils/ls.c (dfree): Free every element of the array.
+++ coreutils/ls.c 43cf5db3a280151500914bbaaf2ac42257b1e5f6
@@ -338,20 +338,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 */
}
@@ -561,7 +559,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
}
}
@@ -1151,13 +1149,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);
}
-------------- next part --------------
2006-04-21 Shaun Jackman <sjackman at gmail.com>
* coreutils/ls.c (dfree): Free every element of the array.
+++ coreutils/ls.c 43cf5db3a280151500914bbaaf2ac42257b1e5f6
@@ -338,20 +338,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 */
}
@@ -561,7 +559,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
}
}
@@ -1151,13 +1149,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
mailing list