Skip to content

Commit

Permalink
Merge pull request #288 from alltilla/filterx-leak-fixes
Browse files Browse the repository at this point in the history
filterx: fix some memory leaks
  • Loading branch information
MrAnno authored Sep 17, 2024
2 parents 33f1b99 + eb93d16 commit 17d3599
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion lib/filterx/expr-compound.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2024 Attila Szakacs
* Copyright (c) 2024 Axoflow
* Copyright (c) 2024 Attila Szakacs <attila.szakacs@axoflow.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -146,13 +147,15 @@ filterx_compound_expr_add(FilterXExpr *s, FilterXExpr *expr)
g_ptr_array_add(self->exprs, expr);
}

/* Takes reference of expr_list */
void
filterx_compound_expr_add_list(FilterXExpr *s, GList *expr_list)
{
for (GList *elem = expr_list; elem; elem = elem->next)
{
filterx_compound_expr_add(s, elem->data);
}
g_list_free(expr_list);
}

FilterXExpr *
Expand Down
8 changes: 5 additions & 3 deletions lib/filterx/expr-generator.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2024 Attila Szakacs
* Copyright (c) 2024 Axoflow
* Copyright (c) 2024 Attila Szakacs <attila.szakacs@axoflow.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -96,14 +97,15 @@ _create_container_free(FilterXExpr *s)
filterx_expr_free_method(s);
}

/* Takes reference of g and fillable_parent */
FilterXExpr *
filterx_generator_create_container_new(FilterXExpr *g, FilterXExpr *fillable_parent)
{
FilterXExprGeneratorCreateContainer *self = g_new0(FilterXExprGeneratorCreateContainer, 1);

filterx_expr_init_instance(&self->super);
self->generator = (FilterXExprGenerator *) filterx_expr_ref(g);
self->fillable_parent = filterx_expr_ref(fillable_parent);
self->generator = (FilterXExprGenerator *) g;
self->fillable_parent = fillable_parent;
self->super.eval = _create_container_eval;
self->super.free_fn = _create_container_free;

Expand Down
16 changes: 12 additions & 4 deletions lib/filterx/filterx-grammar.ym
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* Copyright (c) 2024 Axoflow
* Copyright (c) 2024 Attila Szakacs <attila.szakacs@axoflow.com>
* Copyright (c) 2023 Balazs Scheidler <balazs.scheidler@axoflow.com>
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -220,7 +222,9 @@ generator_assignment
filterx_generator_set_fillable($5, filterx_getattr_new(filterx_expr_ref($1), filterx_config_frozen_string(configuration, $3)));

$$ = filterx_compound_expr_new_va(TRUE,
filterx_setattr_new($1, filterx_config_frozen_string(configuration, $3), filterx_generator_create_container_new($5, $1)),
filterx_setattr_new(filterx_expr_ref($1),
filterx_config_frozen_string(configuration, $3),
filterx_generator_create_container_new(filterx_expr_ref($5), $1)),
$5,
NULL
);
Expand All @@ -231,7 +235,9 @@ generator_assignment
filterx_generator_set_fillable($6, filterx_get_subscript_new(filterx_expr_ref($1), filterx_expr_ref($3)));

$$ = filterx_compound_expr_new_va(TRUE,
filterx_set_subscript_new($1, $3, filterx_generator_create_container_new($6, $1)),
filterx_set_subscript_new(filterx_expr_ref($1),
$3,
filterx_generator_create_container_new(filterx_expr_ref($6), $1)),
$6,
NULL
);
Expand All @@ -242,7 +248,9 @@ generator_assignment
filterx_generator_set_fillable($5, filterx_get_subscript_new(filterx_expr_ref($1), minus_one));

$$ = filterx_compound_expr_new_va(TRUE,
filterx_set_subscript_new($1, NULL, filterx_generator_create_container_new($5, $1)),
filterx_set_subscript_new(filterx_expr_ref($1),
NULL,
filterx_generator_create_container_new(filterx_expr_ref($5), $1)),
$5,
NULL
);
Expand All @@ -255,7 +263,7 @@ generator_assignment

filterx_generator_set_fillable($3, filterx_expr_ref($1));
$$ = filterx_compound_expr_new_va(TRUE,
filterx_assign_new($1, filterx_generator_create_container_new($3, json_func)),
filterx_assign_new($1, filterx_generator_create_container_new(filterx_expr_ref($3), json_func)),
$3,
NULL
);
Expand Down
6 changes: 4 additions & 2 deletions lib/filterx/object-message-value.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* Copyright (c) 2024 Axoflow
* Copyright (c) 2024 Attila Szakacs <attila.szakacs@axoflow.com>
* Copyright (c) 2023 Balazs Scheidler <balazs.scheidler@axoflow.com>
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -224,15 +226,15 @@ _unmarshal_repr(const gchar *repr, gssize repr_len, LogMessageValueType t)
return NULL;
}

/* NOTE: calling map_to_json() on a FilterXMessageBase is less than ideal as
/* NOTE: calling map_to_json() on a FilterXMessageValue is less than ideal as
* we would unmarshal the value and then drop the result. The expectation
* is that the caller would explicitly unmarshall first, cache the result
* and call map_to_json on the unmarshalled object.
*/
static gboolean
_map_to_json(FilterXObject *s, struct json_object **jso, FilterXObject **assoc_object)
{
FilterXObject *unmarshalled_object = filterx_object_unmarshal(filterx_object_ref(s));
FilterXObject *unmarshalled_object = filterx_object_unmarshal(s);

if (unmarshalled_object)
{
Expand Down

0 comments on commit 17d3599

Please sign in to comment.