Merge branch 'jc/rerere-multi'

* jc/rerere-multi:
  rerere: remove an null statement
  rerere: plug memory leaks upon "rerere forget" failure
This commit is contained in:
Junio C Hamano 2016-05-23 14:54:37 -07:00
commit ec34a8b135

View File

@ -1050,8 +1050,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
handle_cache(path, sha1, rerere_path(id, "thisimage")); handle_cache(path, sha1, rerere_path(id, "thisimage"));
if (read_mmfile(&cur, rerere_path(id, "thisimage"))) { if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
free(cur.ptr); free(cur.ptr);
return error("Failed to update conflicted state in '%s'", error("Failed to update conflicted state in '%s'", path);
path); goto fail_exit;
} }
cleanly_resolved = !try_merge(id, path, &cur, &result); cleanly_resolved = !try_merge(id, path, &cur, &result);
free(result.ptr); free(result.ptr);
@ -1060,14 +1060,19 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
break; break;
} }
if (id->collection->status_nr <= id->variant) if (id->collection->status_nr <= id->variant) {
return error("no remembered resolution for '%s'", path); error("no remembered resolution for '%s'", path);
goto fail_exit;
}
filename = rerere_path(id, "postimage"); filename = rerere_path(id, "postimage");
if (unlink(filename)) if (unlink(filename)) {
return (errno == ENOENT if (errno == ENOENT)
? error("no remembered resolution for %s", path) error("no remembered resolution for %s", path);
: error_errno("cannot unlink %s", filename)); else
error_errno("cannot unlink %s", filename);
goto fail_exit;
}
/* /*
* Update the preimage so that the user can resolve the * 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)
item->util = id; item->util = id;
fprintf(stderr, "Forgot resolution for %s\n", path); fprintf(stderr, "Forgot resolution for %s\n", path);
return 0; return 0;
fail_exit:
free(id);
return -1;
} }
int rerere_forget(struct pathspec *pathspec) int rerere_forget(struct pathspec *pathspec)