mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-28 13:03:56 +00:00
Fix x11 display leak (#590)
* Call XCloseDisplay in all return paths Add test to confirm XOpenDisplay leak is plugged * whitespace
This commit is contained in:
parent
8ce3a5dff0
commit
8e7a413ec6
@ -43,5 +43,13 @@ func TestGetSysScale(t *testing.T) {
|
||||
log.Println("SysScale: ", s)
|
||||
|
||||
f := robotgo.ScaleF()
|
||||
log.Println("sclae: ", f)
|
||||
log.Println("scale: ", f)
|
||||
}
|
||||
|
||||
func TestGetTitle(t *testing.T) {
|
||||
// just exercise the function, it used to crash with a segfault + "Maximum
|
||||
// number of clients reached"
|
||||
for i := 0; i < 128; i++ {
|
||||
robotgo.GetTitle()
|
||||
}
|
||||
}
|
||||
|
@ -191,6 +191,7 @@ typedef struct _Bounds Bounds;
|
||||
if (items != NULL) {
|
||||
*items = (uint32_t) nItems;
|
||||
}
|
||||
XCloseDisplay(rDisplay);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,10 @@ bool is_valid() {
|
||||
|
||||
// Get the window PID property
|
||||
void* result = GetWindowProperty(mData, WM_PID,NULL);
|
||||
if (result == NULL) { return false; }
|
||||
if (result == NULL) {
|
||||
XCloseDisplay(rDisplay);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Free result and return true
|
||||
XFree(result);
|
||||
@ -405,6 +408,7 @@ MData get_active(void) {
|
||||
if (window != 0) {
|
||||
// Set and return the foreground window
|
||||
result.XWin = (Window)window;
|
||||
XCloseDisplay(rDisplay);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -494,13 +498,13 @@ void close_window_by_Id(MData m_data){
|
||||
char* get_main_title(){
|
||||
// Check if the window is valid
|
||||
if (!is_valid()) { return "is_valid failed."; }
|
||||
|
||||
|
||||
return get_title_by_hand(mData);
|
||||
}
|
||||
|
||||
char* get_title_by_pid(uintptr pid, int8_t isPid){
|
||||
MData win = set_handle_pid(pid, isPid);
|
||||
return get_title_by_hand(win);
|
||||
return get_title_by_hand(win);
|
||||
}
|
||||
|
||||
char* named(void *result) {
|
||||
|
Loading…
Reference in New Issue
Block a user