@matheusbsbs / matheus-bagliano / commits / acac50dd8c
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 12, 2020 at 21:16 UTC acac50dd8c2c9725841b3e9143d78c6345dc076c
3 files changed +16
object.c
+9
@@ -307,6 +307,15 @@ int object_list_contains(struct object_list *list, struct object *obj)
307 return 0;
308 }
309
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 +
319 /*
320 * A zero-length string to which object_array_entry::name can be
321 * initialized without requiring a malloc/free.
object.h
+2
@@ -151,6 +151,8 @@ struct object_list *object_list_insert(struct object *item,
151
152 int object_list_contains(struct object_list *list, struct object *obj);
153
154 +void object_list_free(struct object_list **list);
155 +
156 /* Object array handling .. */
157 void add_object_array(struct object *obj, const char *name, struct object_array *array);
158 void add_object_array_with_path(struct object *obj, const char *name, struct object_array *array, unsigned mode, const char *path);
pack-bitmap.c
+5
@@ -787,10 +787,15 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
787 bitmap_git->result = wants_bitmap;
788 bitmap_git->haves = haves_bitmap;
789
790 + object_list_free(&wants);
791 + object_list_free(&haves);
792 +
793 return bitmap_git;
794
795 cleanup:
796 free_bitmap_index(bitmap_git);
797 + object_list_free(&wants);
798 + object_list_free(&haves);
799 return NULL;
800 }
801