From 8839434ec07524e32c8940d31e3083cf29d3074a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 21 Oct 2019 17:09:02 -0400 Subject: [PATCH] Fix: param-validation: remove memory leaks The GArray allocated in bt_param_validation_validate is never freed, fix that. Furthermore, there's a spurious call to g_ptr_array_new_with_free_func that shouldn't be there, probably the result of a bad merge or bad edit, causing another leak. Remove that one. Change-Id: I89afeaa7e6ee67b6536daa42dc2c6d74ec79ae0c Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2233 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- src/plugins/common/param-validation/param-validation.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/common/param-validation/param-validation.c b/src/plugins/common/param-validation/param-validation.c index ca80e888..b52332bc 100644 --- a/src/plugins/common/param-validation/param-validation.c +++ b/src/plugins/common/param-validation/param-validation.c @@ -400,10 +400,10 @@ enum bt_param_validation_status bt_param_validation_validate( struct bt_param_validation_map_value_descr map_value_descr; enum bt_param_validation_status status; - ctx.error = NULL; + memset(&ctx, '\0', sizeof(ctx)); + ctx.scope_stack = g_array_new(FALSE, FALSE, sizeof(struct validate_ctx_stack_element)); - g_ptr_array_new_with_free_func(g_free); if (!ctx.scope_stack) { status = BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR; goto end; @@ -417,5 +417,9 @@ end: *error = ctx.error; ctx.error = NULL; + if (ctx.scope_stack) { + g_array_free(ctx.scope_stack, TRUE); + } + return status; } -- 2.34.1