gnotclub / xst

st fork that uses Xresources and some pretty good patches
MIT License
536 stars 74 forks source link

xrdb_load leaking display connections #147

Closed bakkeby closed 1 year ago

bakkeby commented 2 years ago

Just wanted to drop a note here as the https://st.suckless.org/patches/xresources-with-reload-signal/ patch for st refers to this project as a reference.

As-is when reloading X resources using the USR1 signal st leaks display server connections. This will not be noticeable under normal usage but if you reload a lot then after some time new programs will fail to start and fall over with the error of "Maximum amount of clients reached".

This should be reproducible by calling killall -q -USR1 st 200 times or so.

The count of this command should represent the number of display connections:

$ lsof -U | grep -E "^st\s" | wc -l
1

(1 here for one terminal)

As-is this number should be incremented by however many st windows are open every time X resources are loaded.

This has to do with that the xrdb_load function opens a connection to the X display when reloading resources, but does not close said connection when it is done.

https://github.com/gnotclub/xst/blob/293b895061ac52ceb8eeef15d6447a917cf5ccd9/xst.c#L26-L37

Would recommend adding a XCloseDisplay(dpy); call at the end of the function.

neeasade commented 2 years ago

Thank you very much! This is very helpful. When I used xst I would run into this EG here. Will add.