rerere: plug memory leaks upon "rerere forget" failure
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 11, 2016 at 16:19 UTC
8f4496148b643f48ec969f48fdaf5d6d8e6153ed
1 file changed
+17
-8
rerere.c
+17
-8
@@ -1052,8 +1052,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
1052
handle_cache(path, sha1, rerere_path(id, "thisimage"));
1053
if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
1054
free(cur.ptr);
1055
- return error("Failed to update conflicted state in '%s'",
1056
- path);
1055
+ error("Failed to update conflicted state in '%s'", path);
1056
+ goto fail_exit;
1057
}
1058
cleanly_resolved = !try_merge(id, path, &cur, &result);
1059
free(result.ptr);
@@ -1062,14 +1062,19 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
1062
break;
1063
}
1064
1065
- if (id->collection->status_nr <= id->variant)
1066
- return error("no remembered resolution for '%s'", path);
1065
+ if (id->collection->status_nr <= id->variant) {
1066
+ error("no remembered resolution for '%s'", path);
1067
+ goto fail_exit;
1068
+ }
1069
1070
filename = rerere_path(id, "postimage");
1069
- if (unlink(filename))
1070
- return (errno == ENOENT
1071
- ? error("no remembered resolution for %s", path)
1072
- : error("cannot unlink %s: %s", filename, strerror(errno)));
1071
+ if (unlink(filename)) {
1072
+ if (errno == ENOENT)
1073
+ error("no remembered resolution for %s", path);
1074
+ else
1075
+ error("cannot unlink %s: %s", filename, strerror(errno));
1076
+ goto fail_exit;
1077
+ };
1078
1079
/*
1080
* 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)
1093
item->util = id;
1094
fprintf(stderr, "Forgot resolution for %s\n", path);
1095
return 0;
1096
+
1097
+fail_exit:
1098
+ free(id);
1099
+ return -1;
1100
}
1101
1102
int rerere_forget(struct pathspec *pathspec)