From 03a71671e4d8d483ff6d765082e6ebf1df9ef3e5 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 Jan 2020 14:51:41 -0500 Subject: [PATCH] tests: plug memory leak in test_bin_info When running test_bin_info (e.g. through tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu) under Valgrind, I get: ==25792== 1,112 (88 direct, 1,024 indirect) bytes in 1 blocks are definitely lost in loss record 18 of 20 ==25792== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==25792== by 0x55C2B10: g_malloc0 (gmem.c:129) ==25792== by 0x55C86F2: g_option_context_new (goption.c:361) ==25792== by 0x10CB25: main (test_bin_info.c:419) Fix that by calling g_option_context_free. Reported-by: Valgrind Memcheck Change-Id: I9cd9a5ef786484169b9215744861af8cd6f5a9c8 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2739 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- .../flt.lttng-utils.debug-info/test_bin_info.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c index 35cacfad..90698d80 100644 --- a/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c +++ b/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c @@ -415,12 +415,14 @@ int main(int argc, char **argv) int ret; GError *error = NULL; GOptionContext *context; + int status; context = g_option_context_new("- bin info test"); g_option_context_add_main_entries(context, entries, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { fprintf(stderr, "option parsing failed: %s\n", error->message); - exit(EXIT_FAILURE); + status = EXIT_FAILURE; + goto end; } g_snprintf(func_foo_printf_name, FUNC_FOO_NAME_LEN, @@ -432,7 +434,8 @@ int main(int argc, char **argv) if (build_id_to_bin()) { fprintf(stderr, "Failed to parse / missing build id\n"); - exit(EXIT_FAILURE); + status = EXIT_FAILURE; + goto end; } plan_tests(NR_TESTS); @@ -445,5 +448,10 @@ int main(int argc, char **argv) test_bin_info_build_id(opt_debug_info_dir); test_bin_info_debug_link(opt_debug_info_dir); - return EXIT_SUCCESS; + status = EXIT_SUCCESS; + +end: + g_option_context_free(context); + + return status; } -- 2.34.1