Skip to content

Commit 689b8c2

Browse files
bertwesarggitster
authored andcommitted
rerere: fix memory leak if rerere images can't be read
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1675862 commit 689b8c2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

rerere.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,18 @@ static int find_conflict(struct string_list *conflict)
364364
static int merge(const char *name, const char *path)
365365
{
366366
int ret;
367-
mmfile_t cur, base, other;
367+
mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
368368
mmbuffer_t result = {NULL, 0};
369369

370370
if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
371371
return 1;
372372

373373
if (read_mmfile(&cur, rerere_path(name, "thisimage")) ||
374374
read_mmfile(&base, rerere_path(name, "preimage")) ||
375-
read_mmfile(&other, rerere_path(name, "postimage")))
376-
return 1;
375+
read_mmfile(&other, rerere_path(name, "postimage"))) {
376+
ret = 1;
377+
goto out;
378+
}
377379
ret = ll_merge(&result, path, &base, &cur, "", &other, "", 0);
378380
if (!ret) {
379381
FILE *f = fopen(path, "w");
@@ -387,6 +389,7 @@ static int merge(const char *name, const char *path)
387389
strerror(errno));
388390
}
389391

392+
out:
390393
free(cur.ptr);
391394
free(base.ptr);
392395
free(other.ptr);

0 commit comments

Comments
 (0)