commit:     bab8be1e6ef9998ca7285310a4fd135127442500
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  2 15:09:21 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Jan  2 15:09:21 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=bab8be1e

libq/tree: ensure we don't leak scandir results on sorted foreach_pkg

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index 186fb4d..49b2fa1 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1341,9 +1341,12 @@ tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, 
void *priv,
        }
 
        /* allow foreach to be called again on the same open tree */
+       if (ctx->do_sort)
+               scandir_free(ctx->cat_de, ctx->cat_cnt);
        ctx->cat_de = NULL;
        ctx->cat_cur = 0;
        ctx->cat_cnt = 0;
+       ctx->do_sort = 0;
 
        return ret;
 }

Reply via email to