From e2691c425cee2e44a5bf739aa7a51a91d257f971 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Thu, 25 Jan 2018 21:48:08 -0500 Subject: [PATCH] fix display server memory leaks --- gfx/display_servers/dispserv_null.c | 4 ++-- gfx/display_servers/dispserv_win32.c | 7 ++++++- gfx/display_servers/dispserv_x11.c | 5 ++++- gfx/video_display_server.c | 6 +++++- gfx/video_display_server.h | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gfx/display_servers/dispserv_null.c b/gfx/display_servers/dispserv_null.c index be9c799456..83df0a772f 100644 --- a/gfx/display_servers/dispserv_null.c +++ b/gfx/display_servers/dispserv_null.c @@ -23,9 +23,9 @@ static void* null_display_server_init(void) return NULL; } -static void null_display_server_destroy(void) +static void null_display_server_destroy(void *data) { - + (void)data; } static bool null_set_window_opacity(void *data, unsigned opacity) diff --git a/gfx/display_servers/dispserv_win32.c b/gfx/display_servers/dispserv_win32.c index 1d96ce8e71..620b4f5cf2 100644 --- a/gfx/display_servers/dispserv_win32.c +++ b/gfx/display_servers/dispserv_win32.c @@ -93,8 +93,10 @@ static void* win32_display_server_init(void) return dispserv; } -static void win32_display_server_destroy(void) +static void win32_display_server_destroy(void *data) { + dispserv_win32_t *dispserv = (dispserv_win32_t*)data; + #ifdef HAS_TASKBAR_EXT if (g_taskbarList && win32_taskbar_is_created()) { @@ -102,6 +104,9 @@ static void win32_display_server_destroy(void) g_taskbarList = NULL; } #endif + + if (dispserv) + free(dispserv); } static bool win32_set_window_opacity(void *data, unsigned opacity) diff --git a/gfx/display_servers/dispserv_x11.c b/gfx/display_servers/dispserv_x11.c index 51443d0e61..f39faeb9c1 100644 --- a/gfx/display_servers/dispserv_x11.c +++ b/gfx/display_servers/dispserv_x11.c @@ -34,9 +34,12 @@ static void* x11_display_server_init(void) return dispserv; } -static void x11_display_server_destroy(void) +static void x11_display_server_destroy(void *data) { + dispserv_x11_t *dispserv = (dispserv_x11_t*)data; + if (dispserv) + free(dispserv); } static bool x11_set_window_opacity(void *data, unsigned opacity) diff --git a/gfx/video_display_server.c b/gfx/video_display_server.c index b0841ec0fe..94c249190f 100644 --- a/gfx/video_display_server.c +++ b/gfx/video_display_server.c @@ -27,6 +27,8 @@ void* video_display_server_init(void) { enum rarch_display_type type = video_driver_display_type_get(); + video_display_server_destroy(); + switch (type) { case RARCH_DISPLAY_WIN32: @@ -54,7 +56,9 @@ void* video_display_server_init(void) void video_display_server_destroy(void) { - + if (current_display_server && current_display_server->destroy) + if (current_display_server_data) + current_display_server->destroy(current_display_server_data); } bool video_display_server_set_window_opacity(unsigned opacity) diff --git a/gfx/video_display_server.h b/gfx/video_display_server.h index e82203f259..3a193aec2d 100644 --- a/gfx/video_display_server.h +++ b/gfx/video_display_server.h @@ -26,7 +26,7 @@ RETRO_BEGIN_DECLS typedef struct video_display_server { void *(*init)(void); - void (*destroy)(void); + void (*destroy)(void *data); bool (*set_window_opacity)(void *data, unsigned opacity); bool (*set_window_progress)(void *data, int progress, bool finished); const char *ident;