diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-12-14 07:55:46 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-12-14 07:55:46 +0100 |
commit | 9ea1378d046d764642718f1b070689072bde4601 (patch) | |
tree | b15bce1d35006e79f91cc2a985e7b69a77e0fd3d /builtin/commit.c | |
parent | Merge branch 'kz/merge-tree-merge-base' (diff) | |
parent | built-ins: use free() not UNLEAK() if trivial, rm dead code (diff) | |
download | git-9ea1378d046d764642718f1b070689072bde4601.tar.xz git-9ea1378d046d764642718f1b070689072bde4601.zip |
Merge branch 'ab/various-leak-fixes'
Various leak fixes.
* ab/various-leak-fixes:
built-ins: use free() not UNLEAK() if trivial, rm dead code
revert: fix parse_options_concat() leak
cherry-pick: free "struct replay_opts" members
rebase: don't leak on "--abort"
connected.c: free the "struct packed_git"
sequencer.c: fix "opts->strategy" leak in read_strategy_opts()
ls-files: fix a --with-tree memory leak
revision API: call graph_clear() in release_revisions()
unpack-file: fix ancient leak in create_temp_file()
built-ins & libs & helpers: add/move destructors, fix leaks
dir.c: free "ident" and "exclude_per_dir" in "struct untracked_cache"
read-cache.c: clear and free "sparse_checkout_patterns"
commit: discard partial cache before (re-)reading it
{reset,merge}: call discard_index() before returning
tests: mark tests as passing with SANITIZE=leak
Diffstat (limited to 'builtin/commit.c')
-rw-r--r-- | builtin/commit.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 06b1330346..44b763d7cd 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -991,8 +991,11 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct object_id oid; const char *parent = "HEAD"; - if (!active_nr && read_cache() < 0) - die(_("Cannot read index")); + if (!active_nr) { + discard_cache(); + if (read_cache() < 0) + die(_("Cannot read index")); + } if (amend) parent = "HEAD^1"; @@ -1875,8 +1878,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) apply_autostash(git_path_merge_autostash(the_repository)); cleanup: - UNLEAK(author_ident); - UNLEAK(err); - UNLEAK(sb); + strbuf_release(&author_ident); + strbuf_release(&err); + strbuf_release(&sb); return ret; } |