Skip to content

Commit 64fe1e4

Browse files
pks-tgitster
authored andcommitted
builtin/stash: fix leaking pathspec_from_file
The `OPT_PATHSPEC_FROM_FILE()` option maps to `OPT_FILENAME()`, which we know will always allocate memory when passed. We never free the memory though, causing a memory leak. Plug it. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5cca114 commit 64fe1e4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

builtin/stash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
17591759
int quiet = 0;
17601760
int pathspec_file_nul = 0;
17611761
const char *stash_msg = NULL;
1762-
const char *pathspec_from_file = NULL;
1762+
char *pathspec_from_file = NULL;
17631763
struct pathspec ps;
17641764
struct option options[] = {
17651765
OPT_BOOL('k', "keep-index", &keep_index,
@@ -1821,7 +1821,9 @@ static int push_stash(int argc, const char **argv, const char *prefix,
18211821

18221822
ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
18231823
include_untracked, only_staged);
1824+
18241825
clear_pathspec(&ps);
1826+
free(pathspec_from_file);
18251827
return ret;
18261828
}
18271829

t/t3909-stash-pathspec-file.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='stash --pathspec-from-file'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_tick

0 commit comments

Comments
 (0)