From 645ee64da0f837245443842d53621e8fd5ac924f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 30 Jul 2017 09:18:42 +0200 Subject: GRAPHICS: MACGUI: Avoid double free of MacTextWindow --- graphics/macgui/mactextwindow.cpp | 4 +--- graphics/macgui/macwindowmanager.cpp | 10 ++-------- graphics/macgui/macwindowmanager.h | 7 ++++++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 333bdcd3d2..e3e2f16acb 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -28,9 +28,7 @@ namespace Graphics { MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) : - MacWindow(wm->getNextId(), true, true, true, wm) { - - wm->addWindowInitialized(this); + MacWindow(wm->getLastId(), true, true, true, wm) { _font = font; _mactext = new MacText("", _wm, font, fgcolor, bgcolor, maxWidth, textAlignment); diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp index 1e4c49fa76..d3f7d22c4d 100644 --- a/graphics/macgui/macwindowmanager.cpp +++ b/graphics/macgui/macwindowmanager.cpp @@ -176,8 +176,7 @@ MacWindowManager::~MacWindowManager() { MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) { MacWindow *w = new MacWindow(_lastId, scrollable, resizable, editable, this); - _windows.push_back(w); - _windowStack.push_back(w); + addWindowInitialized(w); setActive(getNextId()); @@ -187,8 +186,7 @@ MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool edi MacTextWindow *MacWindowManager::addTextWindow(const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) { MacTextWindow *w = new MacTextWindow(this, font, fgcolor, bgcolor, maxWidth, textAlignment); - _windows.push_back(w); - _windowStack.push_back(w); + addWindowInitialized(w); setActive(getNextId()); @@ -201,10 +199,6 @@ void MacWindowManager::addWindowInitialized(MacWindow *macwindow) { _windowStack.push_back(macwindow); } -int MacWindowManager::getNextId() { - return _lastId++; -} - MacMenu *MacWindowManager::addMenu() { _menu = new MacMenu(getNextId(), _screen->getBounds(), this); diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h index 61f4899481..963fc358dd 100644 --- a/graphics/macgui/macwindowmanager.h +++ b/graphics/macgui/macwindowmanager.h @@ -115,11 +115,16 @@ public: * @param macWindow the window to be added to the registry */ void addWindowInitialized(MacWindow *macwindow); + /** + * Returns the last allocated id + * @return last allocated window id + */ + int getLastId() { return _lastId; } /** * Returns the next available id and the increments the internal counter. * @return next (new) window id that can be used */ - int getNextId(); + int getNextId() { return _lastId++; } /** * Add the menu to the desktop. * Note that the returned menu is empty, and therefore must be filled -- cgit v1.2.3