Skip to content

Commit b07fa8f

Browse files
avargitster
authored andcommitted
remote-curl.c: free memory in cmd_main()
Plug a trivial memory leak in code added in a2d725b (Use an external program to implement fetching with curl, 2009-08-05). To do this have the cmd_main() use a "goto cleanup" pattern, and to return an error of 1 unless we can fall through to the http_cleanup() at the end. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a41e8e7 commit b07fa8f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

remote-curl.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,11 +1472,12 @@ int cmd_main(int argc, const char **argv)
14721472
{
14731473
struct strbuf buf = STRBUF_INIT;
14741474
int nongit;
1475+
int ret = 1;
14751476

14761477
setup_git_directory_gently(&nongit);
14771478
if (argc < 2) {
14781479
error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
1479-
return 1;
1480+
goto cleanup;
14801481
}
14811482

14821483
options.verbosity = 1;
@@ -1508,7 +1509,7 @@ int cmd_main(int argc, const char **argv)
15081509
if (strbuf_getline_lf(&buf, stdin) == EOF) {
15091510
if (ferror(stdin))
15101511
error(_("remote-curl: error reading command stream from git"));
1511-
return 1;
1512+
goto cleanup;
15121513
}
15131514
if (buf.len == 0)
15141515
break;
@@ -1556,12 +1557,15 @@ int cmd_main(int argc, const char **argv)
15561557
break;
15571558
} else {
15581559
error(_("remote-curl: unknown command '%s' from git"), buf.buf);
1559-
return 1;
1560+
goto cleanup;
15601561
}
15611562
strbuf_reset(&buf);
15621563
} while (1);
15631564

15641565
http_cleanup();
1566+
ret = 0;
1567+
cleanup:
1568+
strbuf_release(&buf);
15651569

1566-
return 0;
1570+
return ret;
15671571
}

0 commit comments

Comments
 (0)