Skip to content

Commit 22b09cd

Browse files
mhaggergitster
authored andcommitted
prune_refs(): also free the linked list
At least since v1.7, the elements of the `refs_to_prune` linked list have been leaked. Fix the leak by teaching `prune_refs()` to free the list elements as it processes them. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27d03d0 commit 22b09cd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

refs/files-backend.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,17 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
10571057
strbuf_release(&err);
10581058
}
10591059

1060-
static void prune_refs(struct files_ref_store *refs, struct ref_to_prune *r)
1060+
/*
1061+
* Prune the loose versions of the references in the linked list
1062+
* `*refs_to_prune`, freeing the entries in the list as we go.
1063+
*/
1064+
static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_to_prune)
10611065
{
1062-
while (r) {
1066+
while (*refs_to_prune) {
1067+
struct ref_to_prune *r = *refs_to_prune;
1068+
*refs_to_prune = r->next;
10631069
prune_ref(refs, r);
1064-
r = r->next;
1070+
free(r);
10651071
}
10661072
}
10671073

@@ -1148,7 +1154,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
11481154

11491155
packed_refs_unlock(refs->packed_ref_store);
11501156

1151-
prune_refs(refs, refs_to_prune);
1157+
prune_refs(refs, &refs_to_prune);
11521158
strbuf_release(&err);
11531159
return 0;
11541160
}

0 commit comments

Comments
 (0)