debug-info: free existing build-id in bin_info_set_build_id
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 7 Jan 2020 19:42:34 +0000 (14:42 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 8 Jan 2020 18:07:12 +0000 (18:07 +0000)
When running test
tests/plugins/flt.lttng-utils.debug-info/test_bin_info_i386-linux-gnu, I
see:

Direct leak of 20 byte(s) in 1 object(s) allocated from:
    #0 0x7f623da26d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
    #1 0x7f623ce37b10 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x51b10)
    #2 0x5583ef04ad8f in test_bin_info_build_id /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c:239
    #3 0x5583ef04bd01 in main /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_bin_info.c:445
    #4 0x7f623c7f7b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

This is because a build id is set twice on the same bin_info object in
test_bin_info_build_id.  However, bin_info_set_build_id doesn't free the
existing build id, if there is one, before assigning the new build id.

Fix that by freeing the existing build id, if any, before allocating the
new one.

Reported-by: ASan
Change-Id: I66409294bf11accde6c9d54a5e07572f9a995ff6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2738
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/plugins/lttng-utils/debug-info/bin-info.c

index 72eb818932abe0768ec5605bec71c68571356143..b9e92871141557123cd950c5b365e4b48d4fb88e 100644 (file)
@@ -377,6 +377,9 @@ int bin_info_set_build_id(struct bin_info *bin, uint8_t *build_id,
                goto error;
        }
 
+       /* Free any previously set build id. */
+       g_free(bin->build_id);
+
        /* Set the build id. */
        bin->build_id = g_new0(uint8_t, build_id_len);
        if (!bin->build_id) {
This page took 0.025213 seconds and 4 git commands to generate.