Re: [PATCH v2 09/22] builtin/commit: fix leaking change data contents
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Nov 4, 2024, 22:21 UTC
- Message-ID
- <5jdz52uqizr4zigq7nefgbmchqgtj2tkgwm7gxrbzfhe6oojpf@qjhdgoi2qvgg>
- In-Reply-To
- <9f967dfe5d55ca7150bf3e118279388290f7d28c.1729502824.git.ps@pks.im>
On 24/10/21 11:28AM, Patrick Steinhardt wrote:
> While we free the worktree change data, we never free its contents. Fix > this.
Ah, so this worktree change data was part of the string list and was being freed, but it also had memory allocations itself that were not. Makes sense :)
Show 50 quoted lines
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> builtin/commit.c | 9 ++++++++-
> t/t7500-commit-template-squash-signoff.sh | 1 +
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 8db4e9df0c9..18a55bd1b91 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -728,6 +728,13 @@ static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
> repo_unuse_commit_buffer(the_repository, commit, buffer);
> }
>
> +static void change_data_free(void *util, const char *str UNUSED)
> +{
> + struct wt_status_change_data *d = util;
> + free(d->rename_source);
> + free(d);
> +}
> +
> static int prepare_to_commit(const char *index_file, const char *prefix,
> struct commit *current_head,
> struct wt_status *s,
> @@ -991,7 +998,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> s->use_color = 0;
> committable = run_status(s->fp, index_file, prefix, 1, s);
> s->use_color = saved_color_setting;
> - string_list_clear(&s->change, 1);
> + string_list_clear_func(&s->change, change_data_free);
> } else {
> struct object_id oid;
> const char *parent = "HEAD";
> diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh
> index 4dca8d97a77..379d3ed3413 100755
> --- a/t/t7500-commit-template-squash-signoff.sh
> +++ b/t/t7500-commit-template-squash-signoff.sh
> @@ -7,6 +7,7 @@ test_description='git commit
>
> Tests for template, signoff, squash and -F functions.'
>
> +TEST_PASSES_SANITIZE_LEAK=true
> . ./test-lib.sh
>
> . "$TEST_DIRECTORY"/lib-rebase.sh
> --
> 2.47.0.72.gef8ce8f3d4.dirty
>
>