Valgrind is reporting "still reachable" memory leak (2 blocks) when calling find_device() and FOREACH_DEVICE_DEVLINK against "systemd-249". In my case, they are both called within fstab-generator.c on "systemd-249". Only code modifications, on my end, are within fstab-generator.c

A) Block 1 Memory Leak with find_device() - Defined within ./src/udev/udevadm-util.h
int find_device(const char *id, const char *prefix, sd_device **ret);

Also using, "_cleanup_(sd_device_unrefp) sd_device *ret = NULL;" and passing that into find_device()

B) Block 2 Memory Leak with FOREACH_DEVICE_DEVLINK - Think this leak is caused by find_device() issue.

./src/libsystemd/sd-device/device-util.h

#define FOREACH_DEVICE_DEVLINK(device, devlink)             \
        for (devlink = sd_device_get_devlink_first(device); \
             devlink;                                   \
             devlink = sd_device_get_devlink_next(device))
 }

** However, Valgrind doesn't report any "still reachable" memory leak messages with my exact same code fstab-generator.c  mods on "systemd-250".  Somewhere within "systemd-250" code base, this leak issue was already resolved. Just want to understand what is causing this leak, perhaps a weblink that demonstrates/discusses the bug/issue, and how to fix it?   This way I can create a patch for "systemd-249", unsure if we can upgrade to "systemd-250" anytime in the near future on our end.

Below demonstrates the issue.

Thanks,

Tony

SYSTEMD-249:

[@build systemd-249]# valgrind --leak-check=full --show-leak-kinds=all ./build/systemd-fstab-generator
==234387== Memcheck, a memory error detector
==234387== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==234387== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==234387== Command: ./build/systemd-fstab-generator
==234387==
==234387==
==234387== HEAP SUMMARY:
==234387==     in use at exit: 8,192 bytes in 2 blocks
==234387==   total heap usage: 512 allocs, 510 frees, 4,296,424 bytes allocated
==234387==
==234387== 4,096 bytes in 1 blocks are still reachable in loss record 1 of 2
==234387==    at 0x484186F: malloc (vg_replace_malloc.c:380)
==234387==    by 0x4A269E6: mempool_alloc_tile (mempool.c:46)
==234387==    by 0x4A26A75: mempool_alloc0_tile (mempool.c:65)
==234387==    by 0x4A146A7: hashmap_base_new (hashmap.c:777)
==234387==    by 0x4A14886: hashmap_base_ensure_allocated (hashmap.c:828)
==234387==    by 0x4A148FC: _ordered_hashmap_ensure_allocated (hashmap.c:841)
==234387==    by 0x4ACEA06: device_add_property_aux (sd-device.c:100)
==234387==    by 0x4ACE349: device_add_property_internal (device-internal.h:100)
==234387==    by 0x4ACF533: device_set_syspath (sd-device.c:208)
==234387==    by 0x4ACF6C0: sd_device_new_from_syspath (sd-device.c:228)
==234387==    by 0x4ACFA52: sd_device_new_from_devnum (sd-device.c:247)
==234387==    by 0x4AD0900: sd_device_new_from_stat_rdev (sd-device.c:410)
==234387==
==234387== 4,096 bytes in 1 blocks are still reachable in loss record 2 of 2
==234387==    at 0x484186F: malloc (vg_replace_malloc.c:380)
==234387==    by 0x4A269E6: mempool_alloc_tile (mempool.c:46)
==234387==    by 0x4A26A75: mempool_alloc0_tile (mempool.c:65)
==234387==    by 0x4A146A7: hashmap_base_new (hashmap.c:777)
==234387==    by 0x4A14886: hashmap_base_ensure_allocated (hashmap.c:828)
==234387==    by 0x4A14926: _set_ensure_allocated (hashmap.c:845)
==234387==    by 0x4A17279: _set_put_strdup_full (hashmap.c:1851)
==234387==    by 0x4AD3DEB: device_add_devlink (sd-device.c:1186)
==234387==    by 0x4AD432F: handle_db_line (sd-device.c:1259)
==234387==    by 0x4AD4CB0: device_read_db_internal_filename (sd-device.c:1436)
==234387==    by 0x4AD5147: device_read_db_internal (sd-device.c:1468)
==234387==    by 0x4ACE09D: device_read_db (device-private.h:61)
==234387==
==234387== LEAK SUMMARY:
==234387==    definitely lost: 0 bytes in 0 blocks
==234387==    indirectly lost: 0 bytes in 0 blocks
==234387==      possibly lost: 0 bytes in 0 blocks
==234387==    still reachable: 8,192 bytes in 2 blocks
==234387==         suppressed: 0 bytes in 0 blocks
==234387==
==234387== For lists of detected and suppressed errors, rerun with: -s
==234387== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

SYSTEMD-250:

[build systemd-250]# valgrind --leak-check=full --show-leak-kinds=all ./build/systemd-fstab-generator
==234804== Memcheck, a memory error detector
==234804== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==234804== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==234804== Command: ./build/systemd-fstab-generator
==234804==
==234804==
==234804== HEAP SUMMARY:
==234804==     in use at exit: 0 bytes in 0 blocks
==234804==   total heap usage: 92 allocs, 92 frees, 28,743 bytes allocated
==234804==
==234804== All heap blocks were freed -- no leaks are possible
==234804==
==234804== For lists of detected and suppressed errors, rerun with: -s
==234804== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Reply via email to