From 41c4f4153c673e2be8dad9db2ab122663df295b1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Mar 2018 17:28:01 +0200 Subject: [PATCH 1/3] Use scope guard to ensure that free() is called in wxTLW code No real changes, just make the code safer by ensuring that free() is always called instead of doing it manually. --- src/msw/toplevel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 4c96e1c13c..d83406d831 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -38,6 +38,7 @@ #endif //WX_PRECOMP #include "wx/dynlib.h" +#include "wx/scopeguard.h" #include "wx/tooltip.h" #include "wx/msw/private.h" @@ -438,6 +439,8 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, // don't use DS_SETFONT we don't need the fourth WORD for the font) static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3); DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize); + wxON_BLOCK_EXIT1(free, dlgTemplate); + memset(dlgTemplate, 0, dlgsize); // these values are arbitrary, they won't be used normally anyhow @@ -470,7 +473,6 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, dlgTemplate->style |= DS_MODALFRAME; ret = CreateDialog(dlgTemplate, title, pos, sizeReal); - free(dlgTemplate); } else // !dialog { From 29a12aa846b4c065bcffd09ed8081440fd6fc003 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Mar 2018 17:30:38 +0200 Subject: [PATCH 2/3] Slightly simplify wxTopLevelWindowMSW::Create() Don't use "ret" variable, we can avoid testing it if we just return immediately in case of failure. --- src/msw/toplevel.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index d83406d831..1d525d50f1 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -421,8 +421,7 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, // non-TLW windows wxTopLevelWindows.Append(this); - bool ret = CreateBase(parent, id, pos, sizeReal, style, name); - if ( !ret ) + if ( !CreateBase(parent, id, pos, sizeReal, style, name) ) return false; if ( parent ) @@ -472,14 +471,16 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, if ( style & (wxRESIZE_BORDER | wxCAPTION) ) dlgTemplate->style |= DS_MODALFRAME; - ret = CreateDialog(dlgTemplate, title, pos, sizeReal); + if ( !CreateDialog(dlgTemplate, title, pos, sizeReal) ) + return false; } else // !dialog { - ret = CreateFrame(title, pos, sizeReal); + if ( !CreateFrame(title, pos, sizeReal) ) + return false; } - if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) ) + if ( !(GetWindowStyleFlag() & wxCLOSE_BOX) ) { EnableCloseButton(false); } @@ -488,12 +489,9 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, // itself but for custom windows we have to do it ourselves in order to // make the keyboard indicators (such as underlines for accelerators and // focus rectangles) work under Win2k+ - if ( ret ) - { - MSWUpdateUIState(UIS_INITIALIZE); - } + MSWUpdateUIState(UIS_INITIALIZE); - return ret; + return true; } wxTopLevelWindowMSW::~wxTopLevelWindowMSW() From 95ba7a3ef2b6c648ea57ff5a6b695fff38558346 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 28 Mar 2018 22:41:01 +0200 Subject: [PATCH 3/3] Remove redundant test for wxICONIZE in MSW wxMDIChildFrame wxMINIMIZE and wxICONIZE are one and the same, so it's useless to test for both of them. --- src/msw/mdi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index 47f70e1790..b520a01bb0 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -876,7 +876,7 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, msflags |= WS_THICKFRAME; if (style & wxSYSTEM_MENU) msflags |= WS_SYSMENU; - if ((style & wxMINIMIZE) || (style & wxICONIZE)) + if (style & wxMINIMIZE) msflags |= WS_MINIMIZE; if (style & wxMAXIMIZE) msflags |= WS_MAXIMIZE;