<div dir="auto">FWIW I’ve noticed the same thing with as-event</div><div dir="auto"><div><a href="https://github.com/systemd/systemd/issues/22046">https://github.com/systemd/systemd/issues/22046</a></div><br></div><div dir="auto">I had to drain all events before waiting to fix this.</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 24, 2022 at 14:00 Stephen Hemminger <<a href="mailto:stephen@networkplumber.org">stephen@networkplumber.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">On Mon, 24 Jan 2022 10:33:58 +0800 (CST)<br>
www <<a href="mailto:ouyangxuan10@163.com" target="_blank">ouyangxuan10@163.com</a>> wrote:<br>
<br>
> Hi,<br>
> <br>
> <br>
> 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.<br>
> Refer to the method in SYSTEMd. (such as: ListUnits, GetDynamicUsers)<br>
> <br>
> <br>
> Thanks,<br>
> Byron<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> <br>
> At 2022-01-22 22:25:35, "Dan Nicholson" <<a href="mailto:dbn@endlessos.org" target="_blank">dbn@endlessos.org</a>> wrote:<br>
> <br>
> 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.<br>
> <br>
> <br>
> On Sat, Jan 22, 2022, 3:12 AM www <<a href="mailto:ouyangxuan10@163.com" target="_blank">ouyangxuan10@163.com</a>> wrote:<br>
> <br>
> +Add the implementation code of the method.<br>
> <br>
> <br>
> static int method_load_info(sd_bus_message *message, void *userdata, sd_bus_err *error)<br>
> {<br>
> sd_bus_message *reply = NULL;<br>
> ......<br>
> r = sd_bus_message_read(message. "r", &xxx);<br>
> ......<br>
> r= sd_bus_message_new_return(message, &reply); //<br>
> ......<br>
> r = sd_bus_message_open_container(reply, 'a', "(uuuu)");<br>
> ....<br>
> r = sd_bus_message_append(reply, "(uuuu)", xx, xx ,xx ,xx);<br>
> ......<br>
> r = sd_bus_message_close_container(reply);<br>
> .......<br>
> <br>
> <br>
> return sd_bus_send(NULL, reply, NULL);<br>
> }<br>
> <br>
> <br>
> <br>
> <br>
> Thanks,<br>
> Byron<br>
> <br>
> <br>
> <br>
> At 2022-01-22 14:16:13, "www" <<a href="mailto:ouyangxuan10@163.com" target="_blank">ouyangxuan10@163.com</a>> wrote:<br>
> <br>
> Dear all,<br>
> <br>
> <br>
> 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. <br>
> <br>
> <br>
> 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.<br>
> <br>
> <br>
> code implementation:<br>
> int main()<br>
> {<br>
> ......<br>
> r = sd_bus_open_system(&bus);<br>
> ...<br>
> r = sd_bus_add_object_vtable(bus, ......);<br>
> ......<br>
> r= sd_bus_request_name(bus, "xxx.xx.xx.xxx");<br>
> ......<br>
> <br>
> <br>
> for( ; ; )<br>
> {<br>
> r = sd_bus_process(bus, NULL);<br>
> .......<br>
> r = sd_bus_wait(bus, -1);<br>
> ......<br>
> }<br>
> sd_bus_slot_unref(slot);<br>
> sd_bus_unref(bus);<br>
> }<br>
<br>
Try valgrind or address-sanitizer, they often work to find leaks.<br>
<br>
Also better to pass UINT64_MAX instead of -1 to sd_bus_wait() since it takes uint64_t for the timeout.<br>
<br>
<br>
<br>
</blockquote></div></div>