commit:     dc82e50a316006d339eb0a4aa0d65a9502c41677
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 17 04:45:18 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Dec 17 04:45:18 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dc82e50a

cache: avoid memleak warnings

We leak a bit of memory when reinitializing the caches, but we don't care
because we'll be exiting soon after.  Free the memory in debug builds.

 main.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/main.c b/main.c
index c571ef7..d366bef 100644
--- a/main.c
+++ b/main.c
@@ -1071,15 +1071,19 @@ ret:
 void reinitialize_as_needed(void)
 {
        size_t n;
-       const char *overlay;
+       const char *overlay, *ret = ret;
 
        if (reinitialize)
-               array_for_each(overlays, n, overlay)
-                       initialize_flat(overlay, CACHE_EBUILD, true);
+               array_for_each(overlays, n, overlay) {
+                       ret = initialize_flat(overlay, CACHE_EBUILD, true);
+                       IF_DEBUG(free((void *)ret));
+               }
 
        if (reinitialize_metacache)
-               array_for_each(overlays, n, overlay)
-                       initialize_flat(overlay, CACHE_METADATA, true);
+               array_for_each(overlays, n, overlay) {
+                       ret = initialize_flat(overlay, CACHE_METADATA, true);
+                       IF_DEBUG(free((void *)ret));
+               }
 }
 
 typedef struct {

Reply via email to