Skip to content

Commit 1fe50ec

Browse files
committed
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@gentoo.org>
1 parent b3876d4 commit 1fe50ec

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

libq/dep.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2022 Gentoo Foundation
2+
* Copyright 2005-2025 Gentoo Foundation
33
* Distributed under the terms of the GNU General Public License v2
44
*
55
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
@@ -377,11 +377,13 @@ dep_resolve_tree(dep_node *root, tree_ctx *t)
377377
}
378378

379379
void
380-
dep_flatten_tree(const dep_node *root, array_t *out)
380+
dep_flatten_tree(dep_node *root, array_t *out)
381381
{
382382
if (root->type != DEP_NULL) {
383-
if (root->type == DEP_NORM)
383+
if (root->type == DEP_NORM) {
384384
xarraypush_ptr(out, root->atom);
385+
root->atom = NULL;
386+
}
385387
if (root->children)
386388
dep_flatten_tree(root->children, out);
387389
}

libq/dep.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2005-2022 Gentoo Foundation
2+
* Copyright 2005-2025 Gentoo Foundation
33
* Distributed under the terms of the GNU General Public License v2
44
*/
55

@@ -51,6 +51,6 @@ void dep_print_tree(FILE *fp, const dep_node *root, size_t space, array_t *m, co
5151
void dep_resolve_tree(dep_node *root, tree_ctx *t);
5252
void dep_burn_tree(dep_node *root);
5353
void dep_prune_use(dep_node *root, set *use);
54-
void dep_flatten_tree(const dep_node *root, array_t *out);
54+
void dep_flatten_tree(dep_node *root, array_t *out);
5555

5656
#endif

libq/tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
692692
ret = tree_next_pkg_int(ctx->ebuilddir_cat_ctx);
693693
if (ret == NULL) {
694694
tree_close_cat(ctx->ebuilddir_cat_ctx);
695-
tree_close_pkg(ctx->ebuilddir_pkg_ctx);
695+
if (!cat_ctx->ctx->do_sort || cat_ctx->pkg_ctxs == NULL)
696+
tree_close_pkg(ctx->ebuilddir_pkg_ctx);
696697
ctx->ebuilddir_pkg_ctx = NULL;
697698
}
698699
} while (ret == NULL);

qdepends.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ qdepends_results_cb(tree_pkg_ctx *pkg_ctx, void *priv)
295295
}
296296
}
297297

298+
array_for_each(state->deps, m, atom)
299+
atom_implode(atom);
298300
xarrayfree_int(state->deps);
299301
dep_burn_tree(dep_tree);
300302
}

0 commit comments

Comments
 (0)