<div dir="ltr">You are probably looking for sd_bus_flush_close_unref() for this usecase.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 12, 2020 at 11:00 AM David J <<a href="mailto:emacsd@icloud.com">emacsd@icloud.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>Hello!<br></div><div><br></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></div><div><br></div><div>mem_test.c:<br></div><div><br></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></div><div>compile command: gcc mem_test.c -o mem_test `pkg-config --cflags --libs libsystemd`<br><br></div><div>Valgrind output:<br></div><div><br></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></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></div><div><br></div><div>Thank you,<br></div><div>David J.<br></div><div><br></div><div><br></div><div><br></div></div>_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</blockquote></div>