From 946312fe938bc65093b9b648ec6f0c790f351f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Apr 2022 23:21:40 +0200 Subject: [PATCH] X11: Fix returned clipboard string freed too early The clipboard string should not be freed on SelectionClear. The user may have received it from glfwGetClipboardString and it should remain valid until the next call to a public clipboard string function. (cherry picked from commit f60547ac80602955fe0af1ab05fd3f6ed5941e6b) --- src/x11_window.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/x11_window.c b/src/x11_window.c index 47ffef82..fc081486 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -929,20 +929,6 @@ static Atom writeTargetToProperty(const XSelectionRequestEvent* request) return None; } -static void handleSelectionClear(XEvent* event) -{ - if (event->xselectionclear.selection == _glfw.x11.PRIMARY) - { - free(_glfw.x11.primarySelectionString); - _glfw.x11.primarySelectionString = NULL; - } - else - { - free(_glfw.x11.clipboardString); - _glfw.x11.clipboardString = NULL; - } -} - static void handleSelectionRequest(XEvent* event) { const XSelectionRequestEvent* request = &event->xselectionrequest; @@ -1236,12 +1222,7 @@ static void processEvent(XEvent *event) return; } - if (event->type == SelectionClear) - { - handleSelectionClear(event); - return; - } - else if (event->type == SelectionRequest) + if (event->type == SelectionRequest) { handleSelectionRequest(event); return; @@ -1946,10 +1927,6 @@ void _glfwPushSelectionToManagerX11(void) handleSelectionRequest(&event); break; - case SelectionClear: - handleSelectionClear(&event); - break; - case SelectionNotify: { if (event.xselection.target == _glfw.x11.SAVE_TARGETS)