From 8d98a6e37d122f45439263c96dd50ac2f16b7f5f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 24 Feb 2018 21:53:39 +0100 Subject: [PATCH] Add a FreeMonitor platform API This fixes the leak of a wl_output object everytime a monitor is freed. --- src/cocoa_monitor.m | 4 ++++ src/internal.h | 1 + src/mir_monitor.c | 4 ++++ src/monitor.c | 2 ++ src/null_monitor.c | 4 ++++ src/win32_monitor.c | 4 ++++ src/wl_monitor.c | 6 ++++++ src/x11_monitor.c | 4 ++++ 8 files changed, 29 insertions(+) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index a0dc69ce..986d799e 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -355,6 +355,10 @@ void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { const CGRect bounds = CGDisplayBounds(monitor->ns.displayID); diff --git a/src/internal.h b/src/internal.h index fb0cbc8e..5293c71a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -607,6 +607,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor); const char* _glfwPlatformGetScancodeName(int scancode); int _glfwPlatformGetKeyScancode(int key); +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor); void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos); void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, float* xscale, float* yscale); diff --git a/src/mir_monitor.c b/src/mir_monitor.c index b300cac0..c340701e 100644 --- a/src/mir_monitor.c +++ b/src/mir_monitor.c @@ -80,6 +80,10 @@ void _glfwPollMonitorsMir(void) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { if (xpos) diff --git a/src/monitor.c b/src/monitor.c index 050a046c..f7de5500 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -177,6 +177,8 @@ void _glfwFreeMonitor(_GLFWmonitor* monitor) if (monitor == NULL) return; + _glfwPlatformFreeMonitor(monitor); + _glfwFreeGammaArrays(&monitor->originalRamp); _glfwFreeGammaArrays(&monitor->currentRamp); diff --git a/src/null_monitor.c b/src/null_monitor.c index 007dd1aa..84b41c7e 100644 --- a/src/null_monitor.c +++ b/src/null_monitor.c @@ -32,6 +32,10 @@ ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { } diff --git a/src/win32_monitor.c b/src/win32_monitor.c index 898c7f26..d1d159b3 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -334,6 +334,10 @@ void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* ysc ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { DEVMODEW dm; diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 5598de34..5af74084 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -146,6 +146,12 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ + if (monitor->wl.output) + wl_output_destroy(monitor->wl.output); +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { if (xpos) diff --git a/src/x11_monitor.c b/src/x11_monitor.c index a9bb8a23..f557fe47 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -308,6 +308,10 @@ void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor) ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) +{ +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)