{"thread":{"id":"42287","subject":"[PATCH] rerere: plug memory leaks upon \"rerere forget\" failure","startedAt":"2016-05-11T23:32:34Z","lastAt":"2016-05-19T20:05:15Z","messageCount":3,"participants":["Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"286297","messageId":"xmqqpossi31p.fsf@gitster.mtv.corp.google.com","threadId":"42287","inReplyTo":null,"subject":"[PATCH] rerere: plug memory leaks upon \"rerere forget\" failure","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-11T23:32:34Z","receivedAt":"2016-05-11T23:32:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n rerere.c | 25 +++++++++++++++++--------\n 1 file changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 1693866..a804171 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -1052,8 +1052,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n \t\thandle_cache(path, sha1, rerere_path(id, \"thisimage\"));\n \t\tif (read_mmfile(&cur, rerere_path(id, \"thisimage\"))) {\n \t\t\tfree(cur.ptr);\n-\t\t\treturn error(\"Failed to update conflicted state in '%s'\",\n-\t\t\t\t     path);\n+\t\t\terror(\"Failed to update conflicted state in '%s'\", path);\n+\t\t\tgoto fail_exit;\n \t\t}\n \t\tcleanly_resolved = !try_merge(id, path, &cur, &result);\n \t\tfree(result.ptr);\n@@ -1062,14 +1062,19 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n \t\t\tbreak;\n \t}\n \n-\tif (id->collection->status_nr <= id->variant)\n-\t\treturn error(\"no remembered resolution for '%s'\", path);\n+\tif (id->collection->status_nr <= id->variant) {\n+\t\terror(\"no remembered resolution for '%s'\", path);\n+\t\tgoto fail_exit;\n+\t}\n \n \tfilename = rerere_path(id, \"postimage\");\n-\tif (unlink(filename))\n-\t\treturn (errno == ENOENT\n-\t\t\t? error(\"no remembered resolution for %s\", path)\n-\t\t\t: error(\"cannot unlink %s: %s\", filename, strerror(errno)));\n+\tif (unlink(filename)) {\n+\t\tif (errno == ENOENT)\n+\t\t\terror(\"no remembered resolution for %s\", path);\n+\t\telse\n+\t\t\terror(\"cannot unlink %s: %s\", filename, strerror(errno));\n+\t\tgoto fail_exit;\n+\t};\n \n \t/*\n \t * Update the preimage so that the user can resolve the\n@@ -1088,6 +1093,10 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n \titem->util = id;\n \tfprintf(stderr, \"Forgot resolution for %s\\n\", path);\n \treturn 0;\n+\n+fail_exit:\n+\tfree(id);\n+\treturn -1;\n }\n \n int rerere_forget(struct pathspec *pathspec)\n-- \n2.8.2-679-g91c6421\n"},{"id":"287015","messageId":"573E1758.8090801@kdbg.org","threadId":"42287","inReplyTo":"xmqqpossi31p.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] rerere: plug memory leaks upon \"rerere forget\" failure","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2016-05-19T19:43:20Z","receivedAt":"2016-05-19T19:43:20Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 12.05.2016 um 01:32 schrieb Junio C Hamano:\n> +\tif (unlink(filename)) {\n> +\t\tif (errno == ENOENT)\n> +\t\t\terror(\"no remembered resolution for %s\", path);\n> +\t\telse\n> +\t\t\terror(\"cannot unlink %s: %s\", filename, strerror(errno));\n> +\t\tgoto fail_exit;\n> +\t};\n\nIf you haven't merged this topic yet, you might want to remove this \nsuperfluous empty statement.\n\n-- Hannes\n"},{"id":"287017","messageId":"xmqq60u9izk4.fsf@gitster.mtv.corp.google.com","threadId":"42287","inReplyTo":"573E1758.8090801@kdbg.org","subject":"Re: [PATCH] rerere: plug memory leaks upon \"rerere forget\" failure","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-19T20:05:15Z","receivedAt":"2016-05-19T20:05:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}