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 <cwilson@vigilantsw.com> Helped-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tay Ray Chuan committed
Oct 7, 2011 at 15:40 UTC
9516a598e3ecf39667a35ab2c5aa6cf88e9f7717
1 file changed
+9
-4
builtin/fetch.c
+9
-4
@@ -423,8 +423,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
423
else
424
url = xstrdup("foreign");
425
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
+ }
430
431
for (rm = ref_map; rm; rm = rm->next) {
432
struct ref *ref = NULL;
@@ -506,12 +508,15 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
508
fprintf(stderr, " %s\n", note);
509
}
510
}
509
- free(url);
510
- fclose(fp);
511
+
512
if (rc & STORE_REF_ERROR_DF_CONFLICT)
513
error(_("some local refs could not be updated; try running\n"
514
" 'git remote prune %s' to remove any old, conflicting "
515
"branches"), remote_name);
516
+
517
+ abort:
518
+ free(url);
519
+ fclose(fp);
520
return rc;
521
}
522