summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-08-02 15:33:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-08-03 18:12:36 (GMT)
commitf92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6 (patch)
tree3979a3f381b683906af43e422fefd5523dd88257 /remote.c
parent57efebb9b96847adcd25bab0d2c21c599b8f1954 (diff)
downloadgit-f92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6.zip
git-f92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6.tar.gz
git-f92dbdbc6a8aa5f3979f4bb7a7b9bbc8ec9b4aa6.tar.bz2
revisions API: don't leak memory on argv elements that need free()-ing
Add a "free_removed_argv_elements" member to "struct setup_revision_opt", and use it to fix several memory leaks. We have various memory leaks in APIs that take and munge "const char **argv", e.g. parse_options(). Sometimes these APIs are given the "argv" we get to the "main" function, in which case we don't leak memory, but other times we're giving it the "v" member of a "struct strvec" we created. There's several potential ways to fix those sort of leaks, we could add a "nodup" mode to "struct strvec", which would work for the cases where we push constant strings to it. But that wouldn't work as soon as we used strvec_pushf(), or otherwise needed to duplicate or create a string for that "struct strvec". Let's instead make it the responsibility of the revisions API. If it's going to clobber elements of argv it can also free() them, which it will now do if instructed to do so via "free_removed_argv_elements". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/remote.c b/remote.c
index 1ee2b14..d660641 100644
--- a/remote.c
+++ b/remote.c
@@ -2169,6 +2169,9 @@ static int stat_branch_pair(const char *branch_name, const char *base,
struct object_id oid;
struct commit *ours, *theirs;
struct rev_info revs;
+ struct setup_revision_opt opt = {
+ .free_removed_argv_elements = 1,
+ };
struct strvec argv = STRVEC_INIT;
/* Cannot stat if what we used to build on no longer exists */
@@ -2203,7 +2206,7 @@ static int stat_branch_pair(const char *branch_name, const char *base,
strvec_push(&argv, "--");
repo_init_revisions(the_repository, &revs, NULL);
- setup_revisions(argv.nr, argv.v, &revs, NULL);
+ setup_revisions(argv.nr, argv.v, &revs, &opt);
if (prepare_revision_walk(&revs))
die(_("revision walk setup failed"));