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

[PATCH 3/3] server-info: clean up after writing info/packs

From
Jeff King <peff@peff.net>
Date
Sep 13, 2014, 20:19 UTC
Message-ID
<20140913201938.GC27082@peff.net>
In-Reply-To
<20140913201538.GA24854@peff.net>

We allocate pack information in a static global list but never clean it up. This leaks memory, and means that calling update_server_info twice will generate a buggy file (it will have duplicate entries).

Signed-off-by: Jeff King <peff@peff.net>
---
 server-info.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/server-info.c b/server-info.c
index d54a3d6..31f4a74 100644
--- a/server-info.c
+++ b/server-info.c
@@ -233,6 +233,14 @@ static void init_pack_info(const char *infofile, int force)
 		info[i]->new_num = i;
 }
 
+static void free_pack_info(void)
+{
+	int i;
+	for (i = 0; i < num_pack; i++)
+		free(info[i]);
+	free(info);
+}
+
 static int write_pack_info_file(FILE *fp)
 {
 	int i;
@@ -252,6 +260,7 @@ static int update_info_packs(int force)
 
 	init_pack_info(infofile, force);
 	ret = update_info_file(infofile, write_pack_info_file);
+	free_pack_info();
 	free(infofile);
 	return ret;
 }
-- 
2.1.0.373.g91ca799
Previous: Jeff King
Message 9 of 9 in “repack: call prune_packed_objects() and update_server_info() directly”
  1. repack: call prune_packed_objects() and update_server_info() directlyRené Scharfe, Sep 13, 2014
  2. Stefan BellerSep 13, 2014
  3. Jeff KingSep 13, 2014
  4. 1/3 prune-packed: fix minor memory leakJeff King, Sep 13, 2014
  5. 2/3 make update-server-info more robustJeff King, Sep 13, 2014
  6. René ScharfeSep 14, 2014
  7. Junio C HamanoSep 15, 2014
  8. Jeff KingSep 15, 2014
  9. 3/3 server-info: clean up after writing info/packsJeff King, Sep 13, 2014

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.