From cf53c2cc73d872608858174659bd1f799374590b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 22 Aug 2022 06:07:18 +0300 Subject: [PATCH 5/5] sdl/2: Fix science_report_dialog_popup() theme leak See osdn #45422 Signed-off-by: Marko Lindqvist --- client/gui-sdl/repodlgs.c | 1 + client/gui-sdl/widget_window.c | 22 +++++++++++----------- client/gui-sdl2/repodlgs.c | 1 + client/gui-sdl2/widget_window.c | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/client/gui-sdl/repodlgs.c b/client/gui-sdl/repodlgs.c index d9b82e244f..c8a42f8cd8 100644 --- a/client/gui-sdl/repodlgs.c +++ b/client/gui-sdl/repodlgs.c @@ -3302,6 +3302,7 @@ void science_report_dialog_popup(bool raise) pScienceDlg->pEndWidgetList = pWindow; pBackground = theme_get_background(theme, BACKGROUND_SCIENCEDLG); + FREESURFACE(pWindow->theme); pWindow->theme = ResizeSurface(pBackground, pWindow->size.w, pWindow->size.h, 1); FREESURFACE(pBackground); diff --git a/client/gui-sdl/widget_window.c b/client/gui-sdl/widget_window.c index 6fd4c7d26b..d4c77dc44f 100644 --- a/client/gui-sdl/widget_window.c +++ b/client/gui-sdl/widget_window.c @@ -220,13 +220,13 @@ struct widget *create_window_skeleton(struct gui_layer *pDest, return pWindow; } -struct widget * create_window(struct gui_layer *pDest, SDL_String16 *pTitle, - Uint16 w, Uint16 h, Uint32 flags) +struct widget *create_window(struct gui_layer *pDest, SDL_String16 *pTitle, + Uint16 w, Uint16 h, Uint32 flags) { struct widget *pWindow = create_window_skeleton(pDest, pTitle, flags); resize_window(pWindow, NULL, NULL, w, h); - + return pWindow; } @@ -245,8 +245,8 @@ struct widget * create_window(struct gui_layer *pDest, SDL_String16 *pTitle, } **************************************************************************/ int resize_window(struct widget *pWindow, - SDL_Surface * pBcgd, - SDL_Color * pColor, Uint16 new_w, Uint16 new_h) + SDL_Surface *pBcgd, + SDL_Color *pColor, Uint16 new_w, Uint16 new_h) { SDL_Color color; @@ -254,9 +254,9 @@ int resize_window(struct widget *pWindow, if ((new_w != pWindow->size.w) || (new_h != pWindow->size.h)) { pWindow->size.w = new_w; pWindow->size.h = new_h; - + set_client_area(pWindow); - + if (get_wflags(pWindow) & WF_RESTORE_BACKGROUND) { refresh_widget_background(pWindow); } @@ -266,7 +266,7 @@ int resize_window(struct widget *pWindow, pWindow->size.h, SDL_SWSURFACE); } - + if (pBcgd != pWindow->theme) { FREESURFACE(pWindow->theme); } @@ -281,15 +281,15 @@ int resize_window(struct widget *pWindow, } } else { pWindow->theme = create_surf_alpha(new_w, new_h, SDL_SWSURFACE); - + if (!pColor) { color = *get_theme_color(COLOR_THEME_BACKGROUND); pColor = &color; } - + SDL_FillRect(pWindow->theme, NULL, map_rgba(pWindow->theme->format, *pColor)); - + return 1; } } diff --git a/client/gui-sdl2/repodlgs.c b/client/gui-sdl2/repodlgs.c index ec7f9ef37c..d0edc236d9 100644 --- a/client/gui-sdl2/repodlgs.c +++ b/client/gui-sdl2/repodlgs.c @@ -3373,6 +3373,7 @@ void science_report_dialog_popup(bool raise) pScienceDlg->pEndWidgetList = pWindow; pBackground = theme_get_background(theme, BACKGROUND_SCIENCEDLG); + FREESURFACE(pWindow->theme); pWindow->theme = ResizeSurface(pBackground, pWindow->size.w, pWindow->size.h, 1); FREESURFACE(pBackground); diff --git a/client/gui-sdl2/widget_window.c b/client/gui-sdl2/widget_window.c index e24b86a941..fddee1674c 100644 --- a/client/gui-sdl2/widget_window.c +++ b/client/gui-sdl2/widget_window.c @@ -228,7 +228,7 @@ struct widget *create_window_skeleton(struct gui_layer *pDest, /************************************************************************** Create window widget **************************************************************************/ -struct widget *create_window(struct gui_layer *pDest, utf8_str *title, +struct widget *create_window(struct gui_layer *pDest, utf8_str *title, Uint16 w, Uint16 h, Uint32 flags) { struct widget *pWindow = create_window_skeleton(pDest, title, flags); -- 2.35.1