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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 30, 2024 at 11:13 UTC
64fe1e4a8c8731919b0bb26f6e8b9f8a0f4b0477
2 files changed
+4
-1
builtin/stash.c
+3
-1
@@ -1759,7 +1759,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
1759
int quiet = 0;
1760
int pathspec_file_nul = 0;
1761
const char *stash_msg = NULL;
1762
- const char *pathspec_from_file = NULL;
1762
+ char *pathspec_from_file = NULL;
1763
struct pathspec ps;
1764
struct option options[] = {
1765
OPT_BOOL('k', "keep-index", &keep_index,
@@ -1821,7 +1821,9 @@ static int push_stash(int argc, const char **argv, const char *prefix,
1821
1822
ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
1823
include_untracked, only_staged);
1824
+
1825
clear_pathspec(&ps);
1826
+ free(pathspec_from_file);
1827
return ret;
1828
}
1829
t/t3909-stash-pathspec-file.sh
+1
@@ -2,6 +2,7 @@
2
3
test_description='stash --pathspec-from-file'
4
5
+TEST_PASSES_SANITIZE_LEAK=true
6
. ./test-lib.sh
7
8
test_tick