From 375688c15dd00fe03dbeb2cc063eddb1a38677e1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Wed, 12 Apr 2006 22:36:16 +0000 Subject: fixup a big 'ol memory leak in search_for_named_library() --- ldso/ldso/dl-elf.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 61fff7b0e..857465337 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -136,20 +136,33 @@ static struct elf_resolve * search_for_named_library(const char *name, int secure, const char *path_list, struct dyn_elf **rpnt) { - char *path, *path_n; - char mylibname[2050]; + char *path, *path_n, *mylibname; struct elf_resolve *tpnt; - int done = 0; + int done; if (path_list==NULL) return NULL; - /* We need a writable copy of this string */ - path = _dl_strdup(path_list); - if (!path) { + /* We need a writable copy of this string, but we don't + * need this allocated permanently since we don't want + * to leak memory, so use alloca to put path on the stack */ + done = _dl_strlen(path_list); + path = alloca(done + 1); + + /* another bit of local storage */ + mylibname = alloca(2050); + + /* gcc inlines alloca using a single instruction adjusting + * the stack pointer and no stack overflow check and thus + * no NULL error return. No point leaving in dead code... */ +#if 0 + if (!path || !mylibname) { _dl_dprintf(2, "Out of memory!\n"); _dl_exit(0); } +#endif + + _dl_strcpy(path, path_list); /* Unlike ldd.c, don't bother to eliminate double //s */ @@ -157,6 +170,7 @@ search_for_named_library(const char *name, int secure, const char *path_list, /* : at the beginning or end of path maps to CWD */ /* :: anywhere maps CWD */ /* "" maps to CWD */ + done = 0; path_n = path; do { if (*path == 0) { -- cgit v1.2.3