Skip to content

Commit ec34a8b

Browse files
committed
Merge branch 'jc/rerere-multi'
* jc/rerere-multi: rerere: remove an null statement rerere: plug memory leaks upon "rerere forget" failure
2 parents f895dd7 + d9d501b commit ec34a8b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

rerere.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
10501050
handle_cache(path, sha1, rerere_path(id, "thisimage"));
10511051
if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
10521052
free(cur.ptr);
1053-
return error("Failed to update conflicted state in '%s'",
1054-
path);
1053+
error("Failed to update conflicted state in '%s'", path);
1054+
goto fail_exit;
10551055
}
10561056
cleanly_resolved = !try_merge(id, path, &cur, &result);
10571057
free(result.ptr);
@@ -1060,14 +1060,19 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
10601060
break;
10611061
}
10621062

1063-
if (id->collection->status_nr <= id->variant)
1064-
return error("no remembered resolution for '%s'", path);
1063+
if (id->collection->status_nr <= id->variant) {
1064+
error("no remembered resolution for '%s'", path);
1065+
goto fail_exit;
1066+
}
10651067

10661068
filename = rerere_path(id, "postimage");
1067-
if (unlink(filename))
1068-
return (errno == ENOENT
1069-
? error("no remembered resolution for %s", path)
1070-
: error_errno("cannot unlink %s", filename));
1069+
if (unlink(filename)) {
1070+
if (errno == ENOENT)
1071+
error("no remembered resolution for %s", path);
1072+
else
1073+
error_errno("cannot unlink %s", filename);
1074+
goto fail_exit;
1075+
}
10711076

10721077
/*
10731078
* Update the preimage so that the user can resolve the
@@ -1086,6 +1091,10 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
10861091
item->util = id;
10871092
fprintf(stderr, "Forgot resolution for %s\n", path);
10881093
return 0;
1094+
1095+
fail_exit:
1096+
free(id);
1097+
return -1;
10891098
}
10901099

10911100
int rerere_forget(struct pathspec *pathspec)

0 commit comments

Comments
 (0)