git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Next: Linus Torvalds
Message 1 of 5 in “[RFC] get_pathspec(): free() old buffer if rewriting”
  1. Johannes SchindelinMay 6, 2006
  2. Linus TorvaldsMay 6, 2006
  3. Johannes SchindelinMay 6, 2006
  4. Junio C HamanoMay 7, 2006
  5. Junio C HamanoMay 7, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.