Kaynağa Gözat

X11: Fix function returning before cleanup

The _glfwPlatformSetWindowFloating function would return without freeing
the state array if the window was already in the requested state.
Camilla Löwy 4 yıl önce
ebeveyn
işleme
071d7c0f46
2 değiştirilmiş dosya ile 17 ekleme ve 16 silme
  1. 1 0
      README.md
  2. 16 16
      src/x11_window.c

+ 1 - 0
README.md

@@ -230,6 +230,7 @@ information on what to include when reporting a bug.
    reported (#1112,#1415,#1472,#1616)
  - [X11] Bugfix: Some window attributes were not applied on leaving fullscreen
    (#1863)
+ - [X11] Bugfix: Changing `GLFW_FLOATING` could leak memory
  - [Wayland] Added dynamic loading of all Wayland libraries
  - [Wayland] Removed support for `wl_shell` (#1443)
  - [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432)

+ 16 - 16
src/x11_window.c

@@ -2671,14 +2671,14 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
                     break;
             }
 
-            if (i < count)
-                return;
-
-            XChangeProperty(_glfw.x11.display, window->x11.handle,
-                            _glfw.x11.NET_WM_STATE, XA_ATOM, 32,
-                            PropModeAppend,
-                            (unsigned char*) &_glfw.x11.NET_WM_STATE_ABOVE,
-                            1);
+            if (i == count)
+            {
+                XChangeProperty(_glfw.x11.display, window->x11.handle,
+                                _glfw.x11.NET_WM_STATE, XA_ATOM, 32,
+                                PropModeAppend,
+                                (unsigned char*) &_glfw.x11.NET_WM_STATE_ABOVE,
+                                1);
+            }
         }
         else if (states)
         {
@@ -2688,15 +2688,15 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
                     break;
             }
 
-            if (i == count)
-                return;
-
-            states[i] = states[count - 1];
-            count--;
+            if (i < count)
+            {
+                states[i] = states[count - 1];
+                count--;
 
-            XChangeProperty(_glfw.x11.display, window->x11.handle,
-                            _glfw.x11.NET_WM_STATE, XA_ATOM, 32,
-                            PropModeReplace, (unsigned char*) states, count);
+                XChangeProperty(_glfw.x11.display, window->x11.handle,
+                                _glfw.x11.NET_WM_STATE, XA_ATOM, 32,
+                                PropModeReplace, (unsigned char*) states, count);
+            }
         }
 
         if (states)