Fix: autodisc: make sure auto_discover_source_for_input_as_dir_or_file_rec closes dir master
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 27 Jul 2022 03:31:06 +0000 (23:31 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 1 Aug 2022 18:43:31 +0000 (14:43 -0400)
commitd2b44fef4f0e01f43783115f7c2e97e32c970a52
treeeb78acc15b0a540f2dac2eaab17ebb424d6c5c8c
parent5ce9818ba4e76858b2ef12c81ba75c1306f195d3
Fix: autodisc: make sure auto_discover_source_for_input_as_dir_or_file_rec closes dir

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>
src/autodisc/autodisc.c
This page took 0.034193 seconds and 4 git commands to generate.