commit 54a0941e2bddd450b0797100b3218423b940f833 from: Omar Polo date: Mon Sep 05 09:54:41 2022 UTC release the memory used by the object cache Leak spotted by valgrind. ok stsp@ commit - 932b646a7df3d0578f831622f02348a768cb07bc commit + 54a0941e2bddd450b0797100b3218423b940f833 blob - 5eabe168cdf8761b740fde3af077823aa688346e blob + be7da9be78909deb2cfae4068d9ea7a25d5f2964 --- lib/object_cache.c +++ lib/object_cache.c @@ -359,7 +359,36 @@ check_refcount(struct got_object_id *id, void *data, v return NULL; } #endif + +static const struct got_error * +free_entry(struct got_object_id *id, void *data, void *arg) +{ + struct got_object_cache *cache = arg; + struct got_object_cache_entry *ce = data; + + switch (cache->type) { + case GOT_OBJECT_CACHE_TYPE_OBJ: + got_object_close(ce->data.obj); + break; + case GOT_OBJECT_CACHE_TYPE_TREE: + got_object_tree_close(ce->data.tree); + break; + case GOT_OBJECT_CACHE_TYPE_COMMIT: + got_object_commit_close(ce->data.commit); + break; + case GOT_OBJECT_CACHE_TYPE_TAG: + got_object_tag_close(ce->data.tag); + break; + case GOT_OBJECT_CACHE_TYPE_RAW: + got_object_raw_close(ce->data.raw); + break; + } + free(ce); + + return NULL; +} + void got_object_cache_close(struct got_object_cache *cache) { @@ -387,6 +416,7 @@ got_object_cache_close(struct got_object_cache *cache) #endif if (cache->idset) { + got_object_idset_for_each(cache->idset, free_entry, cache); got_object_idset_free(cache->idset); cache->idset = NULL; }