Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use malloc and free for cv_stack to avoid dangling pointer warning #1417

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scripts/kconfig/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down