]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/stash: fix leaking `pathspec_from_file`
authorPatrick Steinhardt <ps@pks.im>
Mon, 30 Sep 2024 09:13:30 +0000 (11:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2024 18:23:04 +0000 (11:23 -0700)
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>
builtin/stash.c
t/t3909-stash-pathspec-file.sh

index f1acc918d08d727acb61d82f7459975ebfcdec65..1399a1bbe2c222ed3e1c33ac2dd17bd1148f709c 100644 (file)
@@ -1759,7 +1759,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
        int quiet = 0;
        int pathspec_file_nul = 0;
        const char *stash_msg = NULL;
-       const char *pathspec_from_file = NULL;
+       char *pathspec_from_file = NULL;
        struct pathspec ps;
        struct option options[] = {
                OPT_BOOL('k', "keep-index", &keep_index,
@@ -1821,7 +1821,9 @@ static int push_stash(int argc, const char **argv, const char *prefix,
 
        ret = do_push_stash(&ps, stash_msg, quiet, keep_index, patch_mode,
                            include_untracked, only_staged);
+
        clear_pathspec(&ps);
+       free(pathspec_from_file);
        return ret;
 }
 
index 73f2dbdeb022ee71d04e9961da959f60d6eabd5c..83269d0eb4cc42f21f58cb77043aae97f8644f94 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='stash --pathspec-from-file'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_tick