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

[PATCH] read-cache.c: free cache entry when refreshing fails

From
Stefan Beller <sbeller@google.com>
Date
Feb 17, 2015, 18:06 UTC
Message-ID
<1424196374-29509-1-git-send-email-sbeller@google.com>

This fixes a memory leak, when building the cache entries as refresh_cache_entry may decide to return NULL in case of

I am not sure how severe this memory leak is as it was found by scan.coverity.com, CID 290041.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 read-cache.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 9cff715..8d71860 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -725,7 +725,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
 		unsigned int refresh_options)
 {
 	int size, len;
-	struct cache_entry *ce;
+	struct cache_entry *ce, *ret;
 
 	if (!verify_path(path)) {
 		error("Invalid path '%s'", path);
@@ -742,7 +742,13 @@ struct cache_entry *make_cache_entry(unsigned int mode,
 	ce->ce_namelen = len;
 	ce->ce_mode = create_ce_mode(mode);
 
-	return refresh_cache_entry(ce, refresh_options);
+	ret = refresh_cache_entry(ce, refresh_options);
+	if (!ret) {
+		free(ce);
+		return NULL;
+	} else {
+		return ret;
+	}
 }
 
 int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
-- 
2.3.0.81.gc37f363
Next: Junio C Hamano
Message 1 of 3 in “read-cache.c: free cache entry when refreshing fails”
  1. read-cache.c: free cache entry when refreshing failsStefan Beller, Feb 17, 2015
  2. Junio C HamanoFeb 17, 2015
  3. (unknown)Stefan Beller, Feb 17, 2015

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.