[RFC] get_pathspec(): free() old buffer if rewriting
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 6, 2006, 22:04 UTC
- Message-ID
- <Pine.LNX.4.63.0605070003430.6357@wbgn013.biozentrum.uni-wuerzburg.de>
This might be the wrong way to do it, but as it is without this patch, get_pathspec() is leaking memory.
However, it is by no means guaranteed that the input is malloc()ed. The tests run through without problems, but you never know...
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
setup.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c index fe7f884..9c39d6e 100644 --- a/setup.c +++ b/setup.c @@ -126,6 +126,11 @@ const char **get_pathspec(const char *pr prefixlen = prefix ? strlen(prefix) : 0; do { *p = prefix_path(prefix, prefixlen, entry); + if (*p != entry) { + if (*p > entry && *p < entry + strlen(entry)) + *p = strdup(*p); + free((char*)entry); + } } while ((entry = *++p) != NULL); return (const char **) pathspec; }
-- 1.3.2.g9ba6-dirty