Skip to content

Commit acac50d

Browse files
peffgitster
authored andcommitted
pack-bitmap: fix leak of haves/wants object lists
When we do a bitmap-aware revision traversal, we create an object_list for each of the "haves" and "wants" tips. After creating the result bitmaps these are no longer needed or used, but we never free the list memory. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 551cf8b commit acac50d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

object.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ int object_list_contains(struct object_list *list, struct object *obj)
307307
return 0;
308308
}
309309

310+
void object_list_free(struct object_list **list)
311+
{
312+
while (*list) {
313+
struct object_list *p = *list;
314+
*list = p->next;
315+
free(p);
316+
}
317+
}
318+
310319
/*
311320
* A zero-length string to which object_array_entry::name can be
312321
* initialized without requiring a malloc/free.

object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ struct object_list *object_list_insert(struct object *item,
151151

152152
int object_list_contains(struct object_list *list, struct object *obj);
153153

154+
void object_list_free(struct object_list **list);
155+
154156
/* Object array handling .. */
155157
void add_object_array(struct object *obj, const char *name, struct object_array *array);
156158
void add_object_array_with_path(struct object *obj, const char *name, struct object_array *array, unsigned mode, const char *path);

pack-bitmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,15 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
787787
bitmap_git->result = wants_bitmap;
788788
bitmap_git->haves = haves_bitmap;
789789

790+
object_list_free(&wants);
791+
object_list_free(&haves);
792+
790793
return bitmap_git;
791794

792795
cleanup:
793796
free_bitmap_index(bitmap_git);
797+
object_list_free(&wants);
798+
object_list_free(&haves);
794799
return NULL;
795800
}
796801

0 commit comments

Comments
 (0)