aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/multi-pack-index.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-06-11 11:19:22 +0200
committerJunio C Hamano <gitster@pobox.com>2024-06-11 13:15:04 -0700
commit14da26230a7644a2f9dfbc3f43d9d7ab6e0074e9 (patch)
tree600341b6864236888a6508a79bf46e97436ded8b /builtin/multi-pack-index.c
parentrevision: fix memory leak when reversing revisions (diff)
downloadgit-14da26230a7644a2f9dfbc3f43d9d7ab6e0074e9.tar.gz
git-14da26230a7644a2f9dfbc3f43d9d7ab6e0074e9.zip
parse-options: fix leaks for users of OPT_FILENAME
The `OPT_FILENAME()` option will, if set, put an allocated string into the user-provided variable. Consequently, that variable thus needs to be free'd by the caller of `parse_options()`. Some callsites don't though and thus leak memory. Fix those. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/multi-pack-index.c')
-rw-r--r--builtin/multi-pack-index.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 8360932d2e..9cf1a32d65 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -50,7 +50,7 @@ static char const * const builtin_multi_pack_index_usage[] = {
static struct opts_multi_pack_index {
char *object_dir;
const char *preferred_pack;
- const char *refs_snapshot;
+ char *refs_snapshot;
unsigned long batch_size;
unsigned flags;
int stdin_packs;
@@ -135,6 +135,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
N_("refs snapshot for selecting bitmap commits")),
OPT_END(),
};
+ int ret;
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
@@ -157,7 +158,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
if (opts.stdin_packs) {
struct string_list packs = STRING_LIST_INIT_DUP;
- int ret;
read_packs_from_stdin(&packs);
@@ -166,12 +166,17 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.refs_snapshot, opts.flags);
string_list_clear(&packs, 0);
+ free(opts.refs_snapshot);
return ret;
}
- return write_midx_file(opts.object_dir, opts.preferred_pack,
- opts.refs_snapshot, opts.flags);
+
+ ret = write_midx_file(opts.object_dir, opts.preferred_pack,
+ opts.refs_snapshot, opts.flags);
+
+ free(opts.refs_snapshot);
+ return ret;
}
static int cmd_multi_pack_index_verify(int argc, const char **argv,