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

[PATCH] rerere: plug memory leaks upon "rerere forget" failure

From
Junio C Hamano <gitster@pobox.com>
Date
May 11, 2016, 23:32 UTC
Message-ID
<xmqqpossi31p.fsf@gitster.mtv.corp.google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 rerere.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/rerere.c b/rerere.c
index 1693866..a804171 100644
--- a/rerere.c
+++ b/rerere.c
@@ -1052,8 +1052,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
 		handle_cache(path, sha1, rerere_path(id, "thisimage"));
 		if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
 			free(cur.ptr);
-			return error("Failed to update conflicted state in '%s'",
-				     path);
+			error("Failed to update conflicted state in '%s'", path);
+			goto fail_exit;
 		}
 		cleanly_resolved = !try_merge(id, path, &cur, &result);
 		free(result.ptr);
@@ -1062,14 +1062,19 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
 			break;
 	}
 
-	if (id->collection->status_nr <= id->variant)
-		return error("no remembered resolution for '%s'", path);
+	if (id->collection->status_nr <= id->variant) {
+		error("no remembered resolution for '%s'", path);
+		goto fail_exit;
+	}
 
 	filename = rerere_path(id, "postimage");
-	if (unlink(filename))
-		return (errno == ENOENT
-			? error("no remembered resolution for %s", path)
-			: error("cannot unlink %s: %s", filename, strerror(errno)));
+	if (unlink(filename)) {
+		if (errno == ENOENT)
+			error("no remembered resolution for %s", path);
+		else
+			error("cannot unlink %s: %s", filename, strerror(errno));
+		goto fail_exit;
+	};
 
 	/*
 	 * Update the preimage so that the user can resolve the
@@ -1088,6 +1093,10 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
 	item->util = id;
 	fprintf(stderr, "Forgot resolution for %s\n", path);
 	return 0;
+
+fail_exit:
+	free(id);
+	return -1;
 }
 
 int rerere_forget(struct pathspec *pathspec)
-- 
2.8.2-679-g91c6421
Next: Johannes Sixt
Message 1 of 3 in “rerere: plug memory leaks upon "rerere forget" failure”
  1. rerere: plug memory leaks upon "rerere forget" failureJunio C Hamano, May 11, 2016
  2. Johannes SixtMay 19, 2016
  3. Junio C HamanoMay 19, 2016

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.