Skip to content

Commit

Permalink
builtin/commit: fix leaking change data contents
Browse files Browse the repository at this point in the history
While we free the worktree change data, we never free its contents. Fix
this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
pks-t authored and gitster committed Nov 5, 2024
1 parent 3b37315 commit d34b5cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions t/t7500-commit-template-squash-signoff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d34b5cb

Please sign in to comment.