From e4f708da3b6fbc1a0813ae060b3a7b12ecf6850f Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 24 Mar 2015 13:11:15 +0300 Subject: [PATCH 1/4] Fix memory leak: ==15753== 24 bytes in 1 blocks are definitely lost in loss record 22 of 71 ==15753== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==15753== by 0x40BAE1: _glfwPlatformGetVideoModes (wl_monitor.c:216) ==15753== by 0x40B9D6: _glfwPlatformGetMonitors (wl_monitor.c:184) ==15753== by 0x406151: glfwInit (init.c:131) ==15753== by 0x4052AE: main (simple.c:49) --- src/wl_monitor.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wl_monitor.c b/src/wl_monitor.c index fbcefd38d..ff315aa24 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -180,10 +180,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) _GLFWmonitor* origMonitor = _glfw.wl.monitors[i]; monitor = calloc(1, sizeof(_GLFWmonitor)); - monitor->modes = - _glfwPlatformGetVideoModes(origMonitor, - &origMonitor->wl.modesCount); *monitor = *_glfw.wl.monitors[i]; + monitor->modes = _glfwPlatformGetVideoModes(origMonitor, &origMonitor->wl.modesCount); + monitor->modeCount = origMonitor->wl.modesCount; monitors[i] = monitor; } From 1f0c7fe7bb8f81c442bc88d31373b4c30b6f7d12 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 24 Mar 2015 13:15:04 +0300 Subject: [PATCH 2/4] Fix memory leak: ==15831== 368 (32 direct, 336 indirect) bytes in 1 blocks are definitely lost in loss record 60 of 70 ==15831== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==15831== by 0x40B21F: _glfwPlatformInit (wl_init.c:553) ==15831== by 0x40612E: glfwInit (init.c:125) ==15831== by 0x4052AE: main (simple.c:49) --- src/wl_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wl_init.c b/src/wl_init.c index 0269ee34d..d98c828d1 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -612,6 +612,8 @@ void _glfwPlatformTerminate(void) wl_display_flush(_glfw.wl.display); if (_glfw.wl.display) wl_display_disconnect(_glfw.wl.display); + if (_glfw.wl.monitors) + free(_glfw.wl.monitors); } const char* _glfwPlatformGetVersionString(void) From 7409378c7eb5a41cfebdd0988c6bf835d33b2a4a Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 24 Mar 2015 13:26:46 +0300 Subject: [PATCH 3/4] Fix memory leak in wl_monitor.c void _glfwAddOutput(uint32_t name, uint32_t version) Monitor was allocated but not freed --- src/wl_init.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wl_init.c b/src/wl_init.c index d98c828d1..d44a128a3 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -612,8 +612,21 @@ void _glfwPlatformTerminate(void) wl_display_flush(_glfw.wl.display); if (_glfw.wl.display) wl_display_disconnect(_glfw.wl.display); + if (_glfw.wl.monitors) + { + int i; + for (i = 0; i < _glfw.wl.monitorsCount; ++i) + { + if (_glfw.wl.monitors[i]) + { + if (_glfw.wl.monitors[i]->wl.modes) + free(_glfw.wl.monitors[i]->wl.modes); + free(_glfw.wl.monitors[i]); + } + } free(_glfw.wl.monitors); + } } const char* _glfwPlatformGetVersionString(void) From b055af044fd4454aa3aff75b39c5b53788b331d4 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 24 Mar 2015 13:31:05 +0300 Subject: [PATCH 4/4] Fix leak: ==16491== 2,399 (2,176 direct, 223 indirect) bytes in 1 blocks are definitely lost in loss record 64 of 67 ==16491== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16491== by 0x5682D0B: xkb_context_new (in /usr/lib/x86_64-linux-gnu/libxkbcommon.so.0.0.0) ==16491== by 0x40B24B: _glfwPlatformInit (wl_init.c:556) ==16491== by 0x40612E: glfwInit (init.c:125) ==16491== by 0x4052AE: main (simple.c:49) --- src/wl_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wl_init.c b/src/wl_init.c index d44a128a3..407146416 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -627,6 +627,8 @@ void _glfwPlatformTerminate(void) } free(_glfw.wl.monitors); } + + xkb_context_unref(_glfw.wl.xkb.context); } const char* _glfwPlatformGetVersionString(void)