builtin/commit: fix leaking change data contents
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>
Patrick Steinhardt committed
Nov 5, 2024 at 07:17 UTC
d34b5cbf028ffda45928e50884a6ef3aa533e6e5
2 files changed
+9
-1
builtin/commit.c
+8
-1
@@ -728,6 +728,13 @@ static void prepare_amend_commit(struct commit *commit, struct strbuf *sb,
728
repo_unuse_commit_buffer(the_repository, commit, buffer);
729
}
730
731
+static void change_data_free(void *util, const char *str UNUSED)
732
+{
733
+ struct wt_status_change_data *d = util;
734
+ free(d->rename_source);
735
+ free(d);
736
+}
737
+
738
static int prepare_to_commit(const char *index_file, const char *prefix,
739
struct commit *current_head,
740
struct wt_status *s,
@@ -991,7 +998,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
998
s->use_color = 0;
999
committable = run_status(s->fp, index_file, prefix, 1, s);
1000
s->use_color = saved_color_setting;
994
- string_list_clear(&s->change, 1);
1001
+ string_list_clear_func(&s->change, change_data_free);
1002
} else {
1003
struct object_id oid;
1004
const char *parent = "HEAD";
t/t7500-commit-template-squash-signoff.sh
+1
@@ -7,6 +7,7 @@ test_description='git commit
7
8
Tests for template, signoff, squash and -F functions.'
9
10
+TEST_PASSES_SANITIZE_LEAK=true
11
. ./test-lib.sh
12
13
. "$TEST_DIRECTORY"/lib-rebase.sh