From f4a31195bf1918aacb35de915dbc44aaa60c6158 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Tue, 15 Oct 2024 14:35:54 +0200 Subject: [PATCH] Fix: Use malloc and free for cv_stack to avoid dangling pointer warning --- scripts/kconfig/symbol.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 2432298487..3c67663a62 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1097,10 +1097,14 @@ static void sym_check_print_recursive(struct symbol *last_sym) struct symbol *sym, *next_sym; struct menu *menu = NULL; struct property *prop; - struct dep_stack cv_stack; + struct dep_stack *cv_stack = malloc(sizeof(struct dep_stack)); + if (!cv_stack) { + fprintf(stderr, "failed to allocate memory for recursive dependency check\n"); + return; + } if (sym_is_choice_value(last_sym)) { - dep_stack_insert(&cv_stack, last_sym); + dep_stack_insert(cv_stack, last_sym); last_sym = prop_get_symbol(sym_get_choice_prop(last_sym)); } @@ -1109,6 +1113,7 @@ static void sym_check_print_recursive(struct symbol *last_sym) break; if (!stack) { fprintf(stderr, "unexpected recursive dependency error\n"); + free(cv_stack); return; } @@ -1161,8 +1166,9 @@ static void sym_check_print_recursive(struct symbol *last_sym) } } - if (check_top == &cv_stack) + if (check_top == cv_stack) dep_stack_remove(); + free(cv_stack); } static struct symbol *sym_check_expr_deps(struct expr *e)