Will,
thank you very much. I spent my Sunday debugging this thing! Using sd_bus_flush_close_unref() eliminated the memory leak!
Appreciate your help!
On April 12, 2020 at 9:20 PM, William Kennington <william@xxxxxxxxxxxxxxx> wrote:
You are probably looking for sd_bus_flush_close_unref() for this usecase.On Sun, Apr 12, 2020 at 11:00 AM David J <emacsd@xxxxxxxxxx> wrote:_______________________________________________Hello!This is in regards to sd-bus function "sd_bus_open_system", where Valgrind reports possible memory leak. See the following code:mem_test.c:#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
int main(int argc, char *argv[]) {
sd_bus *bus = NULL;
int r = sd_bus_open_system(&bus);
if (r < 0) {
fprintf(stderr, "sd_bus_open_system: %s\n", strerror(-r));
}
bus = sd_bus_unref(bus);
}compile command: gcc mem_test.c -o mem_test `pkg-config --cflags --libs libsystemd`Valgrind output:==4452== Memcheck, a memory error detector
==4452== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4452== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==4452== Command: ./mem_test
==4452==
==4452==
==4452== HEAP SUMMARY:
==4452== in use at exit: 7,736 bytes in 12 blocks
==4452== total heap usage: 17 allocs, 5 frees, 8,045 bytes allocated
==4452==
==4452== LEAK SUMMARY:
==4452== definitely lost: 0 bytes in 0 blocks
==4452== indirectly lost: 0 bytes in 0 blocks
==4452== possibly lost: 3,640 bytes in 11 blocks
==4452== still reachable: 4,096 bytes in 1 blocks
==4452== suppressed: 0 bytes in 0 blocksThe 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!Thank you,David J.
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
_______________________________________________ systemd-devel mailing list systemd-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/systemd-devel