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

[PATCH] Fix a small memory leak in builtin-add

From
Benoit Sigoure <tsuna@lrde.epita.fr>
Date
Oct 29, 2007, 07:00 UTC
Message-ID
<1193641233-3880-2-git-send-email-tsuna@lrde.epita.fr>
In-Reply-To
<1193641233-3880-1-git-send-email-tsuna@lrde.epita.fr>

prune_directory and fill_directory allocated one byte per pathspec and never freed it.

Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
I don't know whether this was intentionnal or not (since it's only a matter of
having small chunks of memory not being reclaimed and I don't think we can
enter these functions twice, so these are not leaks in the sense that the
program will consume more and more memory).  But if it was intentionnal,
wouldn't it be better to put a small comment in the code saying so (so that
casual readers like me won't get surprised).
 builtin-add.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index f9a6580..b8e6094 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -44,6 +44,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 			die("pathspec '%s' did not match any files",
 					pathspec[i]);
 	}
+        free(seen);
 }
 
 static void fill_directory(struct dir_struct *dir, const char **pathspec,
@@ -135,6 +136,7 @@ static void refresh(int verbose, const char **pathspec)
 		if (!seen[i])
 			die("pathspec '%s' did not match any files", pathspec[i]);
 	}
+        free(seen);
 }
 
 static int git_add_config(const char *var, const char *value)
-- 
1.5.3.4.398.g859b
Previous: Benoit SigoureNext: Junio C Hamano
Message 2 of 3 in “core-tutorial: Catch up with current Git”
  1. core-tutorial: Catch up with current GitBenoit Sigoure, Oct 29, 2007
  2. Fix a small memory leak in builtin-addBenoit Sigoure, Oct 29, 2007
  3. Junio C HamanoOct 30, 2007

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.