[systemd-devel] sd_bus_process() + sd_bus_wait() is it not suitable for application?
William Kennington
william at wkennington.com
Tue Jan 25 02:43:09 UTC 2022
FWIW I’ve noticed the same thing with as-event
https://github.com/systemd/systemd/issues/22046
I had to drain all events before waiting to fix this.
On Mon, Jan 24, 2022 at 14:00 Stephen Hemminger <stephen at networkplumber.org>
wrote:
> On Mon, 24 Jan 2022 10:33:58 +0800 (CST)
> www <ouyangxuan10 at 163.com> wrote:
>
> > Hi,
> >
> >
> > When the busctl command is used to call the method corresponding to this
> function, the memory used by the process will increase after 65 ~ 70 times.
> If continue to call, the memory usage will continue to increase.
> > Refer to the method in SYSTEMd. (such as: ListUnits, GetDynamicUsers)
> >
> >
> > Thanks,
> > Byron
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > At 2022-01-22 22:25:35, "Dan Nicholson" <dbn at endlessos.org> wrote:
> >
> > Aren't your leaking reply there? You don't seem to be unreffing it and
> it's not being returned to someone else to do it either.
> >
> >
> > On Sat, Jan 22, 2022, 3:12 AM www <ouyangxuan10 at 163.com> wrote:
> >
> > +Add the implementation code of the method.
> >
> >
> > static int method_load_info(sd_bus_message *message, void *userdata,
> sd_bus_err *error)
> > {
> > sd_bus_message *reply = NULL;
> > ......
> > r = sd_bus_message_read(message. "r", &xxx);
> > ......
> > r= sd_bus_message_new_return(message, &reply); //
> > ......
> > r = sd_bus_message_open_container(reply, 'a', "(uuuu)");
> > ....
> > r = sd_bus_message_append(reply, "(uuuu)", xx, xx ,xx ,xx);
> > ......
> > r = sd_bus_message_close_container(reply);
> > .......
> >
> >
> > return sd_bus_send(NULL, reply, NULL);
> > }
> >
> >
> >
> >
> > Thanks,
> > Byron
> >
> >
> >
> > At 2022-01-22 14:16:13, "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);
> > }
>
> Try valgrind or address-sanitizer, they often work to find leaks.
>
> Also better to pass UINT64_MAX instead of -1 to sd_bus_wait() since it
> takes uint64_t for the timeout.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20220124/c928bfc7/attachment.htm>
More information about the systemd-devel
mailing list