parse: lex: fix memory leaks

This commit is contained in:
2026-05-30 19:50:38 +01:00
parent fec3be2140
commit 5d6f2a5ce8
4 changed files with 22 additions and 11 deletions
+12 -5
View File
@@ -198,11 +198,14 @@ struct bshell_lex_state *lex_state_push(
return state;
}
void lex_state_pop(struct bshell_lex_ctx *ctx)
void lex_state_pop(struct bshell_lex_ctx *ctx, bool no_preserve_root)
{
fx_queue_entry *entry = fx_queue_last(&ctx->lex_state);
if (!entry || !fx_queue_prev(entry)) {
/* don't pop if this is the root state */
if (!entry) {
return;
}
if (!no_preserve_root && !fx_queue_prev(entry)) {
return;
}
@@ -451,6 +454,10 @@ enum bshell_status bshell_lex_ctx_cleanup(struct bshell_lex_ctx *ctx)
fx_string_unref(ctx->lex_tmp);
}
while (!fx_queue_empty(&ctx->lex_state)) {
lex_state_pop(ctx, true);
}
memset(ctx, 0x0, sizeof *ctx);
return BSHELL_SUCCESS;
}
@@ -1228,7 +1235,7 @@ static bool do_lex_state_transition(
if (!recursive) {
for (unsigned int i = 0; i < state->s_nr_terminators; i++) {
if (state->s_terminators[i] == token) {
lex_state_pop(ctx);
lex_state_pop(ctx, false);
return true;
}
}
@@ -1275,7 +1282,7 @@ static bool do_lex_state_transition(
const struct bshell_lex_state_link *link = best_matches[i];
switch (link->l_type) {
case BSHELL_LEX_STATE_LINK_POP:
lex_state_pop(ctx);
lex_state_pop(ctx, false);
result = true;
break;
case BSHELL_LEX_STATE_LINK_PUSH: {