remote-curl.c: free memory in cmd_main()

Plug a trivial memory leak in code added in a2d725b7bdf (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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Mar 4, 2022 at 19:32 UTC b07fa8f1b2004fa7ea7091ba453be894bddfeb3a
1 file changed +8 -4
remote-curl.c
+8 -4
@@ -1472,11 +1472,12 @@ int cmd_main(int argc, const char **argv)
1472 {
1473 struct strbuf buf = STRBUF_INIT;
1474 int nongit;
1475 + int ret = 1;
1476
1477 setup_git_directory_gently(&nongit);
1478 if (argc < 2) {
1479 error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
1479 - return 1;
1480 + goto cleanup;
1481 }
1482
1483 options.verbosity = 1;
@@ -1508,7 +1509,7 @@ int cmd_main(int argc, const char **argv)
1509 if (strbuf_getline_lf(&buf, stdin) == EOF) {
1510 if (ferror(stdin))
1511 error(_("remote-curl: error reading command stream from git"));
1511 - return 1;
1512 + goto cleanup;
1513 }
1514 if (buf.len == 0)
1515 break;
@@ -1556,12 +1557,15 @@ int cmd_main(int argc, const char **argv)
1557 break;
1558 } else {
1559 error(_("remote-curl: unknown command '%s' from git"), buf.buf);
1559 - return 1;
1560 + goto cleanup;
1561 }
1562 strbuf_reset(&buf);
1563 } while (1);
1564
1565 http_cleanup();
1566 + ret = 0;
1567 +cleanup:
1568 + strbuf_release(&buf);
1569
1566 - return 0;
1570 + return ret;
1571 }