git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] get_pathspec(): free() old buffer if rewriting
@ 2006-05-06 22:04 Johannes Schindelin
  2006-05-06 22:37 ` Linus Torvalds
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2006-05-06 22:04 UTC (permalink / raw)
  To: git, junkio


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-05-07  4:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-06 22:04 [RFC] get_pathspec(): free() old buffer if rewriting Johannes Schindelin
2006-05-06 22:37 ` Linus Torvalds
2006-05-06 22:44   ` Johannes Schindelin
2006-05-07  4:26   ` Junio C Hamano
2006-05-07  4:50     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).