commit: dd38aa9ea12be2fecdd938c1f68744156d165fbe
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Aug 24 14:29:57 2025 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Aug 24 14:29:57 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dd38aa9e
libq/tree: fix iterating over EBUILD tree
moving from one cat to the other did not properly clear the pseudo
cat_ctx, which meant a re-using memory manager could (and would) assign
the same pointers again, causing the code to errorneously believe we
were still traversing the same category.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/tree.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libq/tree.c b/libq/tree.c
index 4d3572a..aad6716 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -279,7 +279,7 @@ tree_open_cat(tree_ctx *ctx, const char *name)
return NULL;
}
- cat_ctx = xmalloc(sizeof(*cat_ctx));
+ cat_ctx = xzalloc(sizeof(*cat_ctx));
cat_ctx->name = name;
cat_ctx->fd = fd;
cat_ctx->dir = dir;
@@ -589,12 +589,14 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
tree_ctx *pkgdir = ctx->ebuilddir_ctx;
if (pkgdir == NULL)
- pkgdir = ctx->ebuilddir_ctx =
xzalloc(sizeof(tree_ctx));
+ pkgdir = ctx->ebuilddir_ctx =
xmalloc(sizeof(*pkgdir));
+ ctx->ebuilddir_cat_ctx = NULL;
ctx->ebuilddir_pkg_ctx =
tree_next_pkg_int(cat_ctx);
if (ctx->ebuilddir_pkg_ctx == NULL)
return NULL;
+ memset(pkgdir, 0, sizeof(*pkgdir));
pkgdir->portroot_fd = -1;
pkgdir->tree_fd = cat_ctx->fd;
pkgdir->do_sort = ctx->do_sort;