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>
Bert Wesarg committed
Feb 23, 2010 at 21:11 UTC
689b8c290db9d5880699dd3538134daffc1c55d0
1 file changed
+6
-3
rerere.c
+6
-3
@@ -364,7 +364,7 @@ static int find_conflict(struct string_list *conflict)
364
static int merge(const char *name, const char *path)
365
{
366
int ret;
367
- mmfile_t cur, base, other;
367
+ mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
368
mmbuffer_t result = {NULL, 0};
369
370
if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
@@ -372,8 +372,10 @@ static int merge(const char *name, const char *path)
372
373
if (read_mmfile(&cur, rerere_path(name, "thisimage")) ||
374
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
+ }
379
ret = ll_merge(&result, path, &base, &cur, "", &other, "", 0);
380
if (!ret) {
381
FILE *f = fopen(path, "w");
@@ -387,6 +389,7 @@ static int merge(const char *name, const char *path)
389
strerror(errno));
390
}
391
392
+out:
393
free(cur.ptr);
394
free(base.ptr);
395
free(other.ptr);