From 6ed8408faa8252b45ac58c0362b89dee05c0f9f1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 30 Dec 2019 23:34:29 -0500 Subject: [PATCH] trimmer: free GMatchInfo object in set_bound_from_str When a call to compile_and_match succeeds, it returns an allocated GMatchInfo object in `*match_info`, which is never freed, causing a memory leak: ==3711000== 508 (72 direct, 436 indirect) bytes in 1 blocks are definitely lost in loss record 33 of 42 ==3711000== at 0x483AB65: calloc (vg_replace_malloc.c:762) ==3711000== by 0x49CB7C1: g_malloc0 (in /usr/lib/libglib-2.0.so.0.6200.4) ==3711000== by 0x49BCEAA: ??? (in /usr/lib/libglib-2.0.so.0.6200.4) ==3711000== by 0x49BD310: g_regex_match_full (in /usr/lib/libglib-2.0.so.0.6200.4) ==3711000== by 0x49BDEEA: g_regex_match (in /usr/lib/libglib-2.0.so.0.6200.4) ==3711000== by 0x510CF25: compile_and_match (trimmer.c:187) ==3711000== by 0x510D55D: set_bound_from_str (trimmer.c:378) ==3711000== by 0x510D90A: set_bound_from_param (trimmer.c:463) ==3711000== by 0x510DEBE: init_trimmer_comp_from_params (trimmer.c:568) ==3711000== by 0x510E090: trimmer_init (trimmer.c:643) ==3711000== by 0x4886457: add_component_with_init_method_data (graph.c:971) ==3711000== by 0x4886C28: bt_graph_add_filter_component_with_initialize_method_data (graph.c:1075) Fix that by calling g_match_info_free at the end of the function. Reported-by: Valgrind Memcheck Change-Id: Iee42f63d45f5761e1191dcc6d3f6d47e75a4123c Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2727 Reviewed-by: Francis Deslauriers --- src/plugins/utils/trimmer/trimmer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/utils/trimmer/trimmer.c b/src/plugins/utils/trimmer/trimmer.c index 75104b31..c156c0fe 100644 --- a/src/plugins/utils/trimmer/trimmer.c +++ b/src/plugins/utils/trimmer/trimmer.c @@ -428,6 +428,8 @@ int set_bound_from_str(struct trimmer_comp *trimmer_comp, ret = -1; end: + g_match_info_free(match_info); + return ret; } -- 2.34.1