Closed daniel-abramov closed 4 years ago
Since this doesn't build currently for me, I cannot test this, but I propose to implement Drop
for base::Cookie
by calling xcb_discard_reply()
. This idea needs to be fleshed out so that this call is not made when get_reply()
is used.
(by the way: What happens when something calls get_reply()
multiple times on a cookie? I think that is not well-defined according to XCB. Put differently: Shouldn't the argument of get_reply
be changed from &self
to self
?)
No leak unless your program doesn't call xcb_disconnect
. xcb
keeps track of pending replies & frees them on disconnect.
get_reply
multiple time on a cookie will just block on poll. Moving to self
seems to make sense but for Drop xcb_discard_reply
not so much: it won't leak & some *_unchecked
don't generate a reply so xcb
will generate spurious one for it!
No leak unless your program doesn't call xcb_disconnect. xcb keeps track of pending replies & frees them on disconnect.
That's too late for a releasing resources. By that time the memory might be gone. Most apps which communicate with X server actively would call xcb_disconnect()
only when the app is being closed / releases the rest of the resources after accomplishing the job.
like said in the readme rust-xcb
plans to give us only an interface to xcb. A rust idiomatic probably belongs in a higher level wrapper...
but you're right, there is a problem with rust-xcb
though because we can't call xcb_discard_reply
on cookie and having to call get_reply
is not nice.
It seems that if we request the property via
xcb::xproto::get_property()
, we must callget_reply()
, otherwise the corresponding memory will not be freed and the memory leak will happen. I suspect that happens becauseget_reply()
returns axcb::base::Reply<T>
instance which implementsDrop
which in turn callslibc::free()
to deallocate the memory. However ifget_reply()
is not called, it always leads to a memory leak.