git/builtin
Jeff King 3ea35c64b0 stash: tell setup_revisions() to free our allocated strings
In "git stash show", we do a first pass of parsing our command line
options by splitting them into revision args and stash args. These are
stored in strvecs, and we pass the revision args to setup_revisions().

But setup_revisions() may modify the argv we pass it, causing us to leak
some of the entries. In particular, if it sees a "--" string, that will
be dropped from argv. This is the same as other cases addressed by
f92dbdbc6a (revisions API: don't leak memory on argv elements that need
free()-ing, 2022-08-02), and we should fix it the same way: by passing
the free_removed_argv_elements option to setup_revisions().

The added test here is run only with SANITIZE=leak, without checking its
output, because the behavior of stash with "--" is a little odd:

  1. Running "git stash show" will show --stat output. But running "git
     stash show --" will show --patch.

  2. I'd expect a non-option after "--" to be treated as a pathspec, so:

       git stash show -p 1 -- foo

     would look treat "1" as a stash (a synonym for stash@{1}) and
     restrict the resulting diff to "foo". But it doesn't. We split the
     revision/stash args without any regard to "--". So in the example
     above both "1" and "foo" are stashes. Which is an error, but also:

       git stash show -- foo

     treats "foo" as a stash, not a pathspec.

These are both oddities that we may want to address (or may not, if we
want to retain historical quirks). But they are well outside the scope
of this patch. So for now we'll just let the tests confirm we aren't
leaking without otherwise expecting any behavior. If we later address
either of those points and end up with another test that covers "stash
show --", we can drop this leak-only test.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-09-22 14:24:52 -07:00
..
add.c Merge branch 'lm/add-p-context' 2025-08-04 08:10:33 -07:00
am.c config: drop `git_config_get_bool()` wrapper 2025-07-23 08:15:20 -07:00
annotate.c
apply.c builtin: use default hash when outside a repository 2025-07-01 14:58:24 -07:00
archive.c
backfill.c odb: rename `has_object()` 2025-07-01 14:46:38 -07:00
bisect.c
blame.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
branch.c config: drop `git_config_set_multivar()` wrapper 2025-07-23 08:15:21 -07:00
bugreport.c
bundle.c
cat-file.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
check-attr.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
check-ignore.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
check-mailmap.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
check-ref-format.c
checkout--worker.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
checkout-index.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
checkout.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
clean.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
clone.c config: drop `git_config_set_multivar()` wrapper 2025-07-23 08:15:21 -07:00
column.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
commit-graph.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
commit-tree.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
commit.c Merge branch 'lm/add-p-context' 2025-08-04 08:10:33 -07:00
config.c config: drop `git_config_set_multivar_in_file_gently()` wrapper 2025-07-23 08:15:21 -07:00
count-objects.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
credential-cache--daemon.c config: drop `git_config_get_bool()` wrapper 2025-07-23 08:15:20 -07:00
credential-cache.c
credential-store.c config: drop `git_config_get_int()` wrapper 2025-07-23 08:15:20 -07:00
credential.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
describe.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
diagnose.c
diff-files.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
diff-index.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
diff-pairs.c
diff-tree.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
diff.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
difftool.c odb: rename `repo_read_object_file()` 2025-07-01 14:46:38 -07:00
fast-export.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
fast-import.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
fetch-pack.c
fetch.c config: drop `git_config_get_int()` wrapper 2025-07-23 08:15:20 -07:00
fmt-merge-msg.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
for-each-ref.c Merge branch 'rs/for-each-ref-start-after-marker-fix' 2025-08-11 21:30:15 -07:00
for-each-repo.c
fsck.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
fsmonitor--daemon.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
gc.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
get-tar-commit-id.c
grep.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
hash-object.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
help.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
hook.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
index-pack.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
init-db.c
interpret-trailers.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
log.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
ls-files.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
ls-remote.c builtin: use default hash when outside a repository 2025-07-01 14:58:24 -07:00
ls-tree.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
mailinfo.c
mailsplit.c
merge-base.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
merge-file.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
merge.c Merge branch 'rs/merge-compact-summary' 2025-08-11 21:30:16 -07:00
mktag.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
mktree.c odb: introduce `odb_write_object()` 2025-07-16 22:16:15 -07:00
multi-pack-index.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
mv.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
name-rev.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
notes.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
pack-objects.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
pack-redundant.c Merge branch 'ps/object-store' 2025-07-15 15:18:18 -07:00
pack-refs.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
patch-id.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
prune-packed.c
prune.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
pull.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
push.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
range-diff.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
read-tree.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
rebase.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
receive-pack.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
reflog.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
refs.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
remote-ext.c
remote-fd.c
remote.c Merge branch 'dl/squelch-maybe-uninitialized' 2025-08-07 08:14:38 -07:00
repack.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
replace.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
replay.c
rerere.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
reset.c Merge branch 'lm/add-p-context' 2025-08-04 08:10:33 -07:00
rev-list.c Merge branch 'ps/config-wo-the-repository' 2025-08-04 08:10:33 -07:00
rev-parse.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
revert.c Merge branch 'jk/revert-squelch-compiler-warning' 2025-08-07 08:14:37 -07:00
rm.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
send-pack.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
shortlog.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
show-branch.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
show-index.c builtin: use default hash when outside a repository 2025-07-01 14:58:24 -07:00
show-ref.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
sparse-checkout.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
stash.c stash: tell setup_revisions() to free our allocated strings 2025-09-22 14:24:52 -07:00
stripspace.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
submodule--helper.c Merge branch 'kj/renamed-submodule' 2025-08-05 11:53:56 -07:00
symbolic-ref.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
tag.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
unpack-file.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
unpack-objects.c Merge branch 'ps/object-file-wo-the-repository' 2025-08-05 11:53:55 -07:00
update-index.c config: drop `git_config()` wrapper 2025-07-23 08:15:18 -07:00
update-ref.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
update-server-info.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
upload-archive.c
upload-pack.c
var.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
verify-commit.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
verify-pack.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
verify-tag.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00
worktree.c config: drop `git_config_set_multivar_in_file_gently()` wrapper 2025-07-23 08:15:21 -07:00
write-tree.c config: move Git config parsing into "environment.c" 2025-07-23 08:15:22 -07:00