Skip to content

Commit 9516a59

Browse files
rctaygitster
authored andcommitted
fetch: plug two leaks on error exit in store_updated_refs
Close FETCH_HEAD and release the string url even if we have to leave the function store_updated_refs() early. Reported-by: Chris Wilson <[email protected]> Helped-by: Rene Scharfe <[email protected]> Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6b67e0d commit 9516a59

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

builtin/fetch.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
423423
else
424424
url = xstrdup("foreign");
425425

426-
if (check_everything_connected(ref_map, 0))
427-
return error(_("%s did not send all necessary objects\n"), url);
426+
if (check_everything_connected(ref_map, 0)) {
427+
rc = error(_("%s did not send all necessary objects\n"), url);
428+
goto abort;
429+
}
428430

429431
for (rm = ref_map; rm; rm = rm->next) {
430432
struct ref *ref = NULL;
@@ -506,12 +508,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
506508
fprintf(stderr, " %s\n", note);
507509
}
508510
}
509-
free(url);
510-
fclose(fp);
511+
511512
if (rc & STORE_REF_ERROR_DF_CONFLICT)
512513
error(_("some local refs could not be updated; try running\n"
513514
" 'git remote prune %s' to remove any old, conflicting "
514515
"branches"), remote_name);
516+
517+
abort:
518+
free(url);
519+
fclose(fp);
515520
return rc;
516521
}
517522

0 commit comments

Comments
 (0)