From 0e9dedf3cd197c8fdb59c47e6ccc1910cac64422 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 31 Jan 2018 10:03:33 +0100 Subject: [PATCH] Fixed a memleak in About dialog. Updated the copyright year. --- common/dialog_about/AboutDialog_main.cpp | 64 ++++++++++++------------ common/dialog_about/aboutinfo.h | 12 +++++ common/dialog_about/dialog_about.h | 2 +- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/common/dialog_about/AboutDialog_main.cpp b/common/dialog_about/AboutDialog_main.cpp index 74259622a7..4d7644d4e9 100644 --- a/common/dialog_about/AboutDialog_main.cpp +++ b/common/dialog_about/AboutDialog_main.cpp @@ -64,7 +64,7 @@ static void buildKicadAboutBanner( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aInf aInfo.SetAppName( Pgm().App().GetAppName() ); /* Copyright information */ - aInfo.SetCopyright( "(C) 1992-2017 KiCad Developers Team" ); + aInfo.SetCopyright( "(C) 1992-2018 KiCad Developers Team" ); /* KiCad build version */ wxString version; @@ -256,117 +256,117 @@ static void buildKicadAboutBanner( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aInf wxEmptyString, wxEmptyString, "Catalan (CA)", - KiBitmapNew( lang_catalan_xpm ) ) ); + aInfo.CreateKiBitmap( lang_catalan_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( wxT( "Martin Kratoška" ), wxEmptyString, wxEmptyString, "Czech (CZ)", - KiBitmapNew( lang_cs_xpm ) ) ); + aInfo.CreateKiBitmap( lang_cs_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Jerry Jacobs", wxEmptyString, wxEmptyString, "Dutch (NL)", - KiBitmapNew( lang_nl_xpm ) ) ); + aInfo.CreateKiBitmap( lang_nl_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Vesa Solonen", wxEmptyString, wxEmptyString, "Finnish (FI)", - KiBitmapNew( lang_fi_xpm ) ) ); + aInfo.CreateKiBitmap( lang_fi_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Jean-Pierre Charras", wxEmptyString, wxEmptyString, "French (FR)", - KiBitmapNew( lang_fr_xpm ) ) ); + aInfo.CreateKiBitmap( lang_fr_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( wxT( "Mateusz Skowroński" ), wxEmptyString, wxEmptyString, "Polish (PL)", - KiBitmapNew( lang_pl_xpm ) ) ); + aInfo.CreateKiBitmap( lang_pl_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Kerusey Karyu", wxEmptyString, wxEmptyString, "Polish (PL)", - KiBitmapNew( lang_pl_xpm ) ) ); + aInfo.CreateKiBitmap( lang_pl_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Renie Marquet", wxEmptyString, wxEmptyString, "Portuguese (PT)", - KiBitmapNew( lang_pt_xpm ) ) ); + aInfo.CreateKiBitmap( lang_pt_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Igor Plyatov", wxEmptyString, wxEmptyString, "Russian (RU)", - KiBitmapNew( lang_ru_xpm ) ) ); + aInfo.CreateKiBitmap( lang_ru_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Andrey Fedorushkov", wxEmptyString, wxEmptyString, "Russian (RU)", - KiBitmapNew( lang_ru_xpm ) ) ); + aInfo.CreateKiBitmap( lang_ru_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Eldar Khayrullin", wxEmptyString, wxEmptyString, "Russian (RU)", - KiBitmapNew( lang_ru_xpm ) ) ); + aInfo.CreateKiBitmap( lang_ru_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Pedro Martin del Valle", wxEmptyString, wxEmptyString, "Spanish (ES)", - KiBitmapNew( lang_es_xpm ) ) ); + aInfo.CreateKiBitmap( lang_es_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( wxT( "Iñigo Zuluaga" ), wxEmptyString, wxEmptyString, "Spanish (ES)", - KiBitmapNew( lang_es_xpm ) ) ); + aInfo.CreateKiBitmap( lang_es_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( wxT( "Iñigo Figuero" ), wxEmptyString, wxEmptyString, "Spanish (ES)", - KiBitmapNew( lang_es_xpm ) ) ); + aInfo.CreateKiBitmap( lang_es_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Rafael Sokolowski", wxEmptyString, wxEmptyString, "German (DE)", - KiBitmapNew( lang_de_xpm ) ) ); + aInfo.CreateKiBitmap( lang_de_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Kenta Yonekura", wxEmptyString, wxEmptyString, "Japanese (JA)", - KiBitmapNew( lang_jp_xpm ) ) ); + aInfo.CreateKiBitmap( lang_jp_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Manolis Stefanis", wxEmptyString, wxEmptyString, "Greek (el_GR)", - KiBitmapNew( lang_gr_xpm ) ) ); + aInfo.CreateKiBitmap( lang_gr_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Athanasios Vlastos", wxEmptyString, wxEmptyString, "Greek (el_GR)", - KiBitmapNew( lang_gr_xpm ) ) ); + aInfo.CreateKiBitmap( lang_gr_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Milonas Kostas", wxEmptyString, wxEmptyString, "Greek (el_GR)", - KiBitmapNew( lang_gr_xpm ) ) ); + aInfo.CreateKiBitmap( lang_gr_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Michail Misirlis", wxEmptyString, wxEmptyString, "Greek (el_GR)", - KiBitmapNew( lang_gr_xpm ) ) ); + aInfo.CreateKiBitmap( lang_gr_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Massimo Cioce", wxEmptyString, wxEmptyString, "Italian (IT)", - KiBitmapNew( lang_it_xpm ) ) ); + aInfo.CreateKiBitmap( lang_it_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Marco Ciampa", wxEmptyString, wxEmptyString, "Italian (IT)", - KiBitmapNew( lang_it_xpm ) ) ); + aInfo.CreateKiBitmap( lang_it_xpm ) ) ); aInfo.AddTranslator( new CONTRIBUTOR( "Evgeniy Ivanov", wxEmptyString, wxEmptyString, "Bulgarian (BG)", - KiBitmapNew( lang_bg_xpm ) ) ); + aInfo.CreateKiBitmap( lang_bg_xpm ) ) ); // Maintainer who helper in translations, but not in a specific translation #define OTHERS_IN_TRANSLATION _( "Others" ) @@ -393,17 +393,17 @@ static void buildKicadAboutBanner( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aInf wxEmptyString, wxEmptyString, ICON_CONTRIBUTION, - KiBitmapNew( svg_file_xpm ) ) ); + aInfo.CreateKiBitmap( svg_file_xpm ) ) ); aInfo.AddArtist( new CONTRIBUTOR( "Konstantin Baranovskiy", wxEmptyString, wxEmptyString, ICON_CONTRIBUTION, - KiBitmapNew( svg_file_xpm ) ) ); + aInfo.CreateKiBitmap( svg_file_xpm ) ) ); aInfo.AddArtist( new CONTRIBUTOR( "Fabrizio Tappero", wxEmptyString, wxEmptyString, ICON_CONTRIBUTION, - KiBitmapNew( svg_file_xpm ) ) ); + aInfo.CreateKiBitmap( svg_file_xpm ) ) ); // Program credits for 3d models #define MODELS_3D_CONTRIBUTION _( "3D models by" ) @@ -411,31 +411,31 @@ static void buildKicadAboutBanner( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aInf wxEmptyString, "https://github.com/KiCad/kicad-packages3D/graphs/contributors", MODELS_3D_CONTRIBUTION, - KiBitmapNew( three_d_xpm ) ) ); + aInfo.CreateKiBitmap( three_d_xpm ) ) ); aInfo.AddArtist( new CONTRIBUTOR( "Christophe Boschat", wxEmptyString, wxEmptyString, MODELS_3D_CONTRIBUTION, - KiBitmapNew( three_d_xpm ) ) ); + aInfo.CreateKiBitmap( three_d_xpm ) ) ); aInfo.AddArtist( new CONTRIBUTOR( "Renie Marquet", wxEmptyString, wxEmptyString, MODELS_3D_CONTRIBUTION, - KiBitmapNew( three_d_xpm ) ) ); + aInfo.CreateKiBitmap( three_d_xpm ) ) ); #define SYMBOL_LIB_CONTRIBUTION _( "Symbols by" ) aInfo.AddArtist( new CONTRIBUTOR( "GitHub contributors", wxEmptyString, "https://github.com/KiCad/kicad-symbols/graphs/contributors", SYMBOL_LIB_CONTRIBUTION, - KiBitmapNew( edit_component_xpm ) ) ); + aInfo.CreateKiBitmap( edit_component_xpm ) ) ); #define FOOTPRINT_LIB_CONTRIBUTION _( "Footprints by" ) aInfo.AddArtist( new CONTRIBUTOR( "GitHub contributors", wxEmptyString, "https://github.com/KiCad/kicad-footprints/graphs/contributors", FOOTPRINT_LIB_CONTRIBUTION, - KiBitmapNew( edit_module_xpm ) ) ); + aInfo.CreateKiBitmap( edit_module_xpm ) ) ); // Program credits for package developers. aInfo.AddPackager( new CONTRIBUTOR( "Jean-Samuel Reynaud" ) ); diff --git a/common/dialog_about/aboutinfo.h b/common/dialog_about/aboutinfo.h index cb662159da..fee8117f06 100644 --- a/common/dialog_about/aboutinfo.h +++ b/common/dialog_about/aboutinfo.h @@ -29,6 +29,8 @@ #include #include +#include "bitmap_types.h" + class CONTRIBUTOR; WX_DECLARE_OBJARRAY( CONTRIBUTOR, CONTRIBUTORS ); @@ -102,6 +104,13 @@ public: void SetAppIcon( const wxIcon& aIcon ) { m_appIcon = aIcon; } wxIcon& GetAppIcon() { return m_appIcon; } + ///> Wrapper to manage memory allocation for bitmaps + wxBitmap* CreateKiBitmap( BITMAP_DEF aBitmap ) + { + m_bitmaps.emplace_back( KiBitmapNew( aBitmap ) ); + return m_bitmaps.back().get(); + } + private: CONTRIBUTORS developers; CONTRIBUTORS docwriters; @@ -118,6 +127,9 @@ private: wxString libVersion; wxIcon m_appIcon; + + ///> Bitmaps to be freed when the dialog is closed + std::vector> m_bitmaps; }; diff --git a/common/dialog_about/dialog_about.h b/common/dialog_about/dialog_about.h index 9429a7645c..62a51b00a9 100644 --- a/common/dialog_about/dialog_about.h +++ b/common/dialog_about/dialog_about.h @@ -50,7 +50,7 @@ private: wxBitmap m_picPackagers; wxBitmap m_picLicense; - ABOUT_APP_INFO m_info; + ABOUT_APP_INFO& m_info; public: DIALOG_ABOUT( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aAppInfo );