<html><body><div>Hello!<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>This is in regards to sd-bus function "sd_bus_open_system", where Valgrind reports possible memory leak. See the following code:<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>mem_test.c:<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>#include <stdio.h><br>#include <stdlib.h><br>#include <systemd/sd-bus.h><br><br>int main(int argc, char *argv[]) {<br> sd_bus *bus = NULL;<br><br> int r = sd_bus_open_system(&bus);<br> if (r < 0) {<br> fprintf(stderr, "sd_bus_open_system: %s\n", strerror(-r));<br> }<br> bus = sd_bus_unref(bus);<br>}</div><div><br data-mce-bogus="1"></div><div>compile command: gcc mem_test.c -o mem_test `pkg-config --cflags --libs libsystemd`<br><br data-mce-bogus="1"></div><div>Valgrind output:<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>==4452== Memcheck, a memory error detector<br>==4452== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.<br>==4452== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info<br>==4452== Command: ./mem_test<br>==4452== <br>==4452== <br>==4452== HEAP SUMMARY:<br>==4452== in use at exit: 7,736 bytes in 12 blocks<br>==4452== total heap usage: 17 allocs, 5 frees, 8,045 bytes allocated<br>==4452== <br>==4452== LEAK SUMMARY:<br>==4452== definitely lost: 0 bytes in 0 blocks<br>==4452== indirectly lost: 0 bytes in 0 blocks<br>==4452== possibly lost: 3,640 bytes in 11 blocks<br>==4452== still reachable: 4,096 bytes in 1 blocks<br>==4452== suppressed: 0 bytes in 0 blocks<br></div><div><br data-mce-bogus="1"></div><div>The question is am I doing anything wrong here? Why Valgrind thinks there "might" be memory leak? The interesting part is if I use "sd_bus_open_system", Valgrind is all happy and no warnings at all!<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Thank you,<br data-mce-bogus="1"></div><div>David J.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></body></html>