builtin/notes: fix leaking `struct notes_tree` when merging notes
We allocate a `struct notes_tree` in `merge_commit()` which we then initialize via `init_notes()`. It's not really necessary to allocate the structure though given that we never pass ownership to the caller. Furthermore, the allocation leads to a memory leak because despite its name, `free_notes()` doesn't free the `notes_tree` but only clears it. Fix this issue by converting the code to use an on-stack variable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
1ca57bea4a
commit
187b623eef
|
@ -807,7 +807,7 @@ static int merge_commit(struct notes_merge_options *o)
|
||||||
{
|
{
|
||||||
struct strbuf msg = STRBUF_INIT;
|
struct strbuf msg = STRBUF_INIT;
|
||||||
struct object_id oid, parent_oid;
|
struct object_id oid, parent_oid;
|
||||||
struct notes_tree *t;
|
struct notes_tree t = {0};
|
||||||
struct commit *partial;
|
struct commit *partial;
|
||||||
struct pretty_print_context pretty_ctx;
|
struct pretty_print_context pretty_ctx;
|
||||||
void *local_ref_to_free;
|
void *local_ref_to_free;
|
||||||
|
@ -830,8 +830,7 @@ static int merge_commit(struct notes_merge_options *o)
|
||||||
else
|
else
|
||||||
oidclr(&parent_oid, the_repository->hash_algo);
|
oidclr(&parent_oid, the_repository->hash_algo);
|
||||||
|
|
||||||
CALLOC_ARRAY(t, 1);
|
init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
|
||||||
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
|
|
||||||
|
|
||||||
o->local_ref = local_ref_to_free =
|
o->local_ref = local_ref_to_free =
|
||||||
refs_resolve_refdup(get_main_ref_store(the_repository),
|
refs_resolve_refdup(get_main_ref_store(the_repository),
|
||||||
|
@ -839,7 +838,7 @@ static int merge_commit(struct notes_merge_options *o)
|
||||||
if (!o->local_ref)
|
if (!o->local_ref)
|
||||||
die(_("failed to resolve NOTES_MERGE_REF"));
|
die(_("failed to resolve NOTES_MERGE_REF"));
|
||||||
|
|
||||||
if (notes_merge_commit(o, t, partial, &oid))
|
if (notes_merge_commit(o, &t, partial, &oid))
|
||||||
die(_("failed to finalize notes merge"));
|
die(_("failed to finalize notes merge"));
|
||||||
|
|
||||||
/* Reuse existing commit message in reflog message */
|
/* Reuse existing commit message in reflog message */
|
||||||
|
@ -853,7 +852,7 @@ static int merge_commit(struct notes_merge_options *o)
|
||||||
is_null_oid(&parent_oid) ? NULL : &parent_oid,
|
is_null_oid(&parent_oid) ? NULL : &parent_oid,
|
||||||
0, UPDATE_REFS_DIE_ON_ERR);
|
0, UPDATE_REFS_DIE_ON_ERR);
|
||||||
|
|
||||||
free_notes(t);
|
free_notes(&t);
|
||||||
strbuf_release(&msg);
|
strbuf_release(&msg);
|
||||||
ret = merge_abort(o);
|
ret = merge_abort(o);
|
||||||
free(local_ref_to_free);
|
free(local_ref_to_free);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
test_description='Test notes merging with manual conflict resolution'
|
test_description='Test notes merging with manual conflict resolution'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
# Set up a notes merge scenario with different kinds of conflicts
|
# Set up a notes merge scenario with different kinds of conflicts
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
test_description='Test notes merging at various fanout levels'
|
test_description='Test notes merging at various fanout levels'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
verify_notes () {
|
verify_notes () {
|
||||||
|
|
Loading…
Reference in New Issue