The `dir` variable does not get released if the code goes to the `end`
or `error` labels, leaking the GDir. Move the variable to the function
scope and release it before returning.
Fixes this, found by Valgrind:
==
2456047== 32,824 (8 direct, 32,816 indirect) bytes in 1 blocks are definitely lost in loss record 36 of 37
==
2456047== at 0x4845888: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==
2456047== by 0x49A9B19: g_malloc (gmem.c:125)
==
2456047== by 0x49BEDD4: UnknownInlinedFun (gstrfuncs.c:424)
==
2456047== by 0x49BEDD4: g_memdup2 (gstrfuncs.c:417)
==
2456047== by 0x498D0D7: UnknownInlinedFun (gdir.c:117)
==
2456047== by 0x498D0D7: g_dir_open (gdir.c:145)
==
2456047== by 0x12BE5A: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:613)
==
2456047== by 0x12BFEC: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:639)
==
2456047== by 0x12BFEC: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:639)
==
2456047== by 0x12BFEC: auto_discover_source_for_input_as_dir_or_file_rec (autodisc.c:639)
==
2456047== by 0x12C1B9: auto_discover_source_for_input_as_dir_or_file (autodisc.c:710)
==
2456047== by 0x12C2BA: auto_discover_source_components (autodisc.c:753)
==
2456047== by 0x1247A6: bt_config_convert_from_args (babeltrace2-cfg-cli-args.c:4270)
==
2456047== by 0x1262B7: bt_config_cli_args_create (babeltrace2-cfg-cli-args.c:4951)
Change-Id: I2145d588c80fb47b5f3475a6a68cc67bb683edb6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8612
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
{
auto_source_discovery_internal_status status;
GError *error = NULL;
+ GDir *dir = NULL;
if (g_file_test(input->str, G_FILE_TEST_IS_REGULAR)) {
/* It's a file. */
component_class_restrict, log_level, auto_disc,
interrupter);
} else if (g_file_test(input->str, G_FILE_TEST_IS_DIR)) {
- GDir *dir;
const gchar *dirent;
gsize saved_input_len;
int dir_status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH;
} while (dirent);
status = dir_status;
-
- g_dir_close(dir);
} else {
BT_LOGD("Skipping %s, not a file or directory", input->str);
status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH;
status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR;
end:
+ if (dir) {
+ g_dir_close(dir);
+ }
if (error) {
g_error_free(error);