Skip to content

Commit

Permalink
filterx/filterx-expr: fix potential memory leak for expr_text
Browse files Browse the repository at this point in the history
In case an expr is optimized we might be setting the location
of exprs multiple times, prepare for this case by freeing expr_text
before setting it first.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Jan 9, 2025
1 parent aef340f commit 830c565
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/filterx/filterx-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ filterx_expr_set_location_with_text(FilterXExpr *self, CFG_LTYPE *lloc, const gc
self->lloc = g_new0(CFG_LTYPE, 1);
*self->lloc = *lloc;

if (debug_flag && text)
self->expr_text = g_strdup(text);
if (debug_flag && text && text != self->expr_text)
{
g_free(self->expr_text);
self->expr_text = g_strdup(text);
}
}

void
Expand All @@ -48,6 +51,7 @@ filterx_expr_set_location(FilterXExpr *self, CfgLexer *lexer, CFG_LTYPE *lloc)
*self->lloc = *lloc;
if (debug_flag)
{
g_free(self->expr_text);
GString *res = g_string_sized_new(0);
cfg_source_extract_source_text(lexer, lloc, res);
self->expr_text = g_string_free(res, FALSE);
Expand Down

0 comments on commit 830c565

Please sign in to comment.