[systemd-devel] sd_bus_process() + sd_bus_wait() is it not suitable for application?
Lennart Poettering
mzerqung at 0pointer.de
Fri Jan 28 14:11:20 UTC 2022
On Sa, 22.01.22 14:08, www (ouyangxuan10 at 163.com) wrote:
> Dear all,
>
>
> When using sd_bus_process() + sd_bus_wait() to implement the application(Service), call the methods function on the service can obtain the correct information. Run a certain number of times will lead to insufficient memory and memleak does occur.
>
>
> It should not be a problem with the DBUS method, because a single call does not increase memory, it needs to call the method 65 ~ 70 times, and you will see the memory increase. After stopping the call, the memory will not decrease. It seems that it has nothing to do with the time interval when the method is called.
>
>
> code implementation:
> int main()
> {
> ......
> r = sd_bus_open_system(&bus);
> ...
> r = sd_bus_add_object_vtable(bus, ......);
> ......
> r= sd_bus_request_name(bus, "xxx.xx.xx.xxx");
> ......
>
>
> for( ; ; )
> {
> r = sd_bus_process(bus, NULL);
> .......
> r = sd_bus_wait(bus, -1);
> ......
> }
> sd_bus_slot_unref(slot);
> sd_bus_unref(bus);
> }
Maybe the callback handlers you added in the vtable keep some objects
pinned?
Also note that unreffing the bus in the end is typically not enough,
if it still has messages queued. Use sd_bus_flush() + sd_bus_close()
first (or combine them in one sd_bus_flush_close_unref()).
Otherwise it might happen that messages still not flushed out at the
end remain pinned.
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list