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>