Skip to content

Commit 5a1e1e5

Browse files
pks-tgitster
authored andcommitted
builtin/describe: fix leaking array when running diff-index
When running git-describe(1) with `--dirty`, we will set up a `struct rev_info` with arguments for git-diff-index(1). The way we assemble the arguments it causes two memory leaks though: - We never release the `struct strvec`. - `setup_revisions()` may end up removing some entries from the `strvec`, which we wouldn't free even if we released the struct. While we could plug those leaks, this is ultimately unnecessary as the arguments we pass are part of a static array anyway. So instead, refactor the code to drop the `struct strvec` and just pass this static array directly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8e2e287 commit 5a1e1e5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/describe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,6 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
695695
} else if (dirty) {
696696
struct lock_file index_lock = LOCK_INIT;
697697
struct rev_info revs;
698-
struct strvec args = STRVEC_INIT;
699698
int fd;
700699

701700
setup_work_tree();
@@ -710,8 +709,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
710709
repo_update_index_if_able(the_repository, &index_lock);
711710

712711
repo_init_revisions(the_repository, &revs, prefix);
713-
strvec_pushv(&args, diff_index_args);
714-
if (setup_revisions(args.nr, args.v, &revs, NULL) != 1)
712+
713+
if (setup_revisions(ARRAY_SIZE(diff_index_args) - 1,
714+
diff_index_args, &revs, NULL) != 1)
715715
BUG("malformed internal diff-index command line");
716716
run_diff_index(&revs, 0);
717717

0 commit comments

Comments
 (0)