commit: 1fe50ec0bdc6265da3b34d5df912405728f55238 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Fri Aug 29 18:35:08 2025 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Fri Aug 29 18:35:08 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1fe50ec0
qdepends: fix invalid memory accesses - make dep_flatten_tree move the atom, such that it won't get freed before being used - make tree not free the pseudo pkg when it is from the cache Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> libq/dep.c | 8 +++++--- libq/dep.h | 4 ++-- libq/tree.c | 3 ++- qdepends.c | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libq/dep.c b/libq/dep.c index 389e506..f49e764 100644 --- a/libq/dep.c +++ b/libq/dep.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2022 Gentoo Foundation + * Copyright 2005-2025 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - <[email protected]> @@ -377,11 +377,13 @@ dep_resolve_tree(dep_node *root, tree_ctx *t) } void -dep_flatten_tree(const dep_node *root, array_t *out) +dep_flatten_tree(dep_node *root, array_t *out) { if (root->type != DEP_NULL) { - if (root->type == DEP_NORM) + if (root->type == DEP_NORM) { xarraypush_ptr(out, root->atom); + root->atom = NULL; + } if (root->children) dep_flatten_tree(root->children, out); } diff --git a/libq/dep.h b/libq/dep.h index 68d5c75..093b08f 100644 --- a/libq/dep.h +++ b/libq/dep.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2022 Gentoo Foundation + * Copyright 2005-2025 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 */ @@ -51,6 +51,6 @@ void dep_print_tree(FILE *fp, const dep_node *root, size_t space, array_t *m, co void dep_resolve_tree(dep_node *root, tree_ctx *t); void dep_burn_tree(dep_node *root); void dep_prune_use(dep_node *root, set *use); -void dep_flatten_tree(const dep_node *root, array_t *out); +void dep_flatten_tree(dep_node *root, array_t *out); #endif diff --git a/libq/tree.c b/libq/tree.c index 643c7a0..139e0a0 100644 --- a/libq/tree.c +++ b/libq/tree.c @@ -692,7 +692,8 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) ret = tree_next_pkg_int(ctx->ebuilddir_cat_ctx); if (ret == NULL) { tree_close_cat(ctx->ebuilddir_cat_ctx); - tree_close_pkg(ctx->ebuilddir_pkg_ctx); + if (!cat_ctx->ctx->do_sort || cat_ctx->pkg_ctxs == NULL) + tree_close_pkg(ctx->ebuilddir_pkg_ctx); ctx->ebuilddir_pkg_ctx = NULL; } } while (ret == NULL); diff --git a/qdepends.c b/qdepends.c index 6afcb1c..e4be97f 100644 --- a/qdepends.c +++ b/qdepends.c @@ -295,6 +295,8 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv) } } + array_for_each(state->deps, m, atom) + atom_implode(atom); xarrayfree_int(state->deps); dep_burn_tree(dep_tree); }
