Skip to content

test-bus-chat: LeakSanitizer: detected memory leaks #6481

@evverx

Description

@evverx

How to reproduce:

$ env -i ./build/test-bus-chat
Failed to connect to user bus: No such file or directory
Failed to connect to bus, skipping tests.

=================================================================
==6781==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1824 byte(s) in 1 object(s) allocated from:
    #0 0x7f374cd1d020 in calloc (/lib64/libasan.so.3+0xc7020)
    #1 0x7f374c7bedcb in sd_bus_new ../src/libsystemd/sd-bus/sd-bus.c:175
    #2 0x7f374c7c5cd2 in sd_bus_open_user ../src/libsystemd/sd-bus/sd-bus.c:1138
    #3 0x55be9773076b in server_init ../src/libsystemd/sd-bus/test-bus-chat.c:70
    #4 0x55be977334d6 in main ../src/libsystemd/sd-bus/test-bus-chat.c:526
    #5 0x7f374bedc400 in __libc_start_main (/lib64/libc.so.6+0x20400)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f374cd1d210 in realloc (/lib64/libasan.so.3+0xc7210)
    #1 0x7f374c62f487 in greedy_realloc ../src/basic/alloc-util.c:57
    #2 0x7f374c7bf06f in sd_bus_new ../src/libsystemd/sd-bus/sd-bus.c:191
    #3 0x7f374c7c5cd2 in sd_bus_open_user ../src/libsystemd/sd-bus/sd-bus.c:1138
    #4 0x55be9773076b in server_init ../src/libsystemd/sd-bus/test-bus-chat.c:70
    #5 0x55be977334d6 in main ../src/libsystemd/sd-bus/test-bus-chat.c:526
    #6 0x7f374bedc400 in __libc_start_main (/lib64/libc.so.6+0x20400)

SUMMARY: AddressSanitizer: 1888 byte(s) leaked in 2 allocation(s).

The test has been failing under asan since a132bef was merged. It seems that the following patch fixes the leak:

diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 40b6c46..261152b 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1141,7 +1141,7 @@ _public_ int sd_bus_open_user(sd_bus **ret) {

         r = bus_set_address_user(b);
         if (r < 0)
-                return r;
+                goto fail;

         b->bus_client = true;
         b->is_user = true;

, but I haven't tested it yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Programming errors, that need preferential fixingsd-bus

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions