From 2492783bd87d534e4eb1d6a00f082772e7b03172 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Sun, 16 Nov 2014 03:00:35 +0900 Subject: Avoid possible memory leaks in case of exceptions Change-Id: I06525aa32bc17464291126ed676809e23e4227b1 --- starmath/source/edit.cxx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'starmath') diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx index 672a7757eca5..681789b896be 100644 --- a/starmath/source/edit.cxx +++ b/starmath/source/edit.cxx @@ -49,6 +49,7 @@ #include "document.hxx" #include "config.hxx" #include "accessibility.hxx" +#include #define SCROLL_LINE 24 @@ -336,7 +337,7 @@ void SmEditWindow::Command(const CommandEvent& rCEvt) GetParent()->ToTop(); Point aPoint = rCEvt.GetMousePosPixel(); - PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU)); + boost::scoped_ptr pPopupMenu(new PopupMenu(SmResId(RID_COMMANDMENU))); // added for replaceability of context menus Menu* pMenu = NULL; @@ -349,15 +350,13 @@ void SmEditWindow::Command(const CommandEvent& rCEvt) { if ( pMenu ) { - delete pPopupMenu; - pPopupMenu = (PopupMenu*) pMenu; + pPopupMenu.reset((PopupMenu*) pMenu); } } pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl)); pPopupMenu->Execute( this, aPoint ); - delete pPopupMenu; bForwardEvt = false; } else if (rCEvt.GetCommand() == COMMAND_WHEEL) @@ -1094,13 +1093,12 @@ void SmEditWindow::DeleteEditView( SmViewShell & /*rView*/ ) { if (pEditView) { - EditEngine *pEditEngine = pEditView->GetEditEngine(); + boost::scoped_ptr pEditEngine(pEditView->GetEditEngine()); if (pEditEngine) { pEditEngine->SetStatusEventHdl( Link() ); pEditEngine->RemoveView( pEditView ); } - delete pEditView; pEditView = 0; } } -- cgit