[systemd-devel] sd-bus memory check
David J
emacsd at icloud.com
Sun Apr 12 16:45:33 UTC 2020
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 blocks
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!
Thank you,
David J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20200412/43d3bafa/attachment.htm>
More information about the systemd-devel
mailing list