[Libreoffice-commits] core.git: cui/source

Takeshi Abe tabe at fixedpoint.jp
Sat Jul 26 10:22:29 PDT 2014


 cui/source/customize/cfg.cxx       |   46 ++++++++++---------------------------
 cui/source/customize/macropg.cxx   |    4 +--
 cui/source/dialogs/SpellDialog.cxx |   22 +++++++----------
 3 files changed, 24 insertions(+), 48 deletions(-)

New commits:
commit 77b74fe9def6fa37d09600e81f9d88c3a3b4293b
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sun Jul 27 02:13:34 2014 +0900

    Avoid possible memory leaks in case of exceptions
    
    Change-Id: I4c9d1746d43642e1be2dd1e72a1b689d3fae1ae6

diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index bf0f657..8d10cce 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -94,6 +94,7 @@
 #include <com/sun/star/util/thePathSettings.hpp>
 
 #include "dlgname.hxx"
+#include <boost/scoped_ptr.hpp>
 
 #define PRTSTR(x) OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
 
@@ -2403,7 +2404,7 @@ IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
         OUString aNewName( stripHotKey( pMenuData->GetName() ) );
         OUString aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
 
-        SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
+        boost::scoped_ptr<SvxNameDialog> pNameDialog(new SvxNameDialog( this, aNewName, aDesc ));
         pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU );
         pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
 
@@ -2415,17 +2416,14 @@ IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
 
             GetSaveInData()->SetModified( true );
         }
-
-        // #i68101# Memory leak (!)
-        delete pNameDialog;
     }
     else if (sIdent == "move")
     {
         SvxConfigEntry* pMenuData = GetTopLevelSelection();
 
-        SvxMainMenuOrganizerDialog* pDialog =
+        boost::scoped_ptr<SvxMainMenuOrganizerDialog> pDialog(
             new SvxMainMenuOrganizerDialog( this,
-                GetSaveInData()->GetEntries(), pMenuData );
+                GetSaveInData()->GetEntries(), pMenuData ));
 
         if ( pDialog->Execute() == RET_OK )
         {
@@ -2435,8 +2433,6 @@ IMPL_LINK( SvxMenuConfigPage, MenuSelectHdl, MenuButton *, pButton )
 
             GetSaveInData()->SetModified( true );
         }
-
-        delete pDialog;
     }
     else
         return sal_False;
@@ -2451,7 +2447,7 @@ IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
         OUString aNewName;
         OUString aDesc = CUI_RESSTR( RID_SVXSTR_SUBMENU_NAME );
 
-        SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
+        boost::scoped_ptr<SvxNameDialog> pNameDialog(new SvxNameDialog( this, aNewName, aDesc ));
         pNameDialog->SetHelpId( HID_SVX_CONFIG_NAME_SUBMENU );
         pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_ADD_SUBMENU ) );
 
@@ -2468,8 +2464,6 @@ IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
 
             GetSaveInData()->SetModified( true );
         }
-
-        delete pNameDialog;
     }
     else if (sIdent == "addseparator")
     {
@@ -2490,7 +2484,7 @@ IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
         OUString aNewName( stripHotKey( pEntry->GetName() ) );
         OUString aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
 
-        SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
+        boost::scoped_ptr<SvxNameDialog> pNameDialog(new SvxNameDialog( this, aNewName, aDesc ));
         pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_MENU_ITEM );
         pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_MENU ) );
 
@@ -2502,8 +2496,6 @@ IMPL_LINK( SvxMenuConfigPage, EntrySelectHdl, MenuButton *, pButton )
 
             GetSaveInData()->SetModified( true );
         }
-
-        delete pNameDialog;
     }
     else
     {
@@ -2532,9 +2524,9 @@ IMPL_LINK( SvxMenuConfigPage, NewMenuHdl, Button *, pButton )
 {
     (void)pButton;
 
-    SvxMainMenuOrganizerDialog* pDialog =
+    boost::scoped_ptr<SvxMainMenuOrganizerDialog> pDialog(
         new SvxMainMenuOrganizerDialog( 0,
-            GetSaveInData()->GetEntries(), NULL, true );
+            GetSaveInData()->GetEntries(), NULL, true ));
 
     if ( pDialog->Execute() == RET_OK )
     {
@@ -2543,8 +2535,6 @@ IMPL_LINK( SvxMenuConfigPage, NewMenuHdl, Button *, pButton )
         GetSaveInData()->SetModified( true );
     }
 
-    delete pDialog;
-
     return 0;
 }
 
@@ -3062,7 +3052,7 @@ IMPL_LINK( SvxToolbarConfigPage, ToolbarSelectHdl, MenuButton *, pButton )
             OUString aNewName( stripHotKey( pToolbar->GetName() ) );
             OUString aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
 
-            SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
+            boost::scoped_ptr<SvxNameDialog> pNameDialog(new SvxNameDialog( this, aNewName, aDesc ));
             pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR );
             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
 
@@ -3080,9 +3070,6 @@ IMPL_LINK( SvxToolbarConfigPage, ToolbarSelectHdl, MenuButton *, pButton )
                 m_pTopLevelListBox->SetEntryData( nSelectionPos, pToolbar );
                 m_pTopLevelListBox->SelectEntryPos( nSelectionPos );
             }
-
-            delete pNameDialog;
-
             break;
         }
         case ID_DEFAULT_STYLE:
@@ -3151,7 +3138,7 @@ IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
             OUString aNewName( stripHotKey( pEntry->GetName() ) );
             OUString aDesc = CUI_RESSTR( RID_SVXSTR_LABEL_NEW_NAME );
 
-            SvxNameDialog* pNameDialog = new SvxNameDialog( this, aNewName, aDesc );
+            boost::scoped_ptr<SvxNameDialog> pNameDialog(new SvxNameDialog( this, aNewName, aDesc ));
             pNameDialog->SetHelpId( HID_SVX_CONFIG_RENAME_TOOLBAR_ITEM );
             pNameDialog->SetText( CUI_RESSTR( RID_SVXSTR_RENAME_TOOLBAR ) );
 
@@ -3163,8 +3150,6 @@ IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
 
                 bNeedsApply = true;
             }
-
-            delete pNameDialog;
             break;
         }
         case ID_DEFAULT_COMMAND:
@@ -3283,10 +3268,10 @@ IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
                 }
             }
 
-            SvxIconSelectorDialog* pIconDialog =
+            boost::scoped_ptr<SvxIconSelectorDialog> pIconDialog(
                 new SvxIconSelectorDialog( 0,
                     GetSaveInData()->GetImageManager(),
-                    GetSaveInData()->GetParentImageManager() );
+                    GetSaveInData()->GetParentImageManager() ));
 
             if ( pIconDialog->Execute() == RET_OK )
             {
@@ -3341,9 +3326,6 @@ IMPL_LINK( SvxToolbarConfigPage, EntrySelectHdl, MenuButton *, pButton )
                     }
                 }
             }
-
-            delete pIconDialog;
-
             break;
         }
         case ID_RESET_SYMBOL:
@@ -4416,7 +4398,7 @@ IMPL_LINK( SvxToolbarConfigPage, NewToolbarHdl, Button *, pButton )
     OUString aNewURL =
         generateCustomURL( GetSaveInData()->GetEntries() );
 
-    SvxNewToolbarDialog* pNameDialog = new SvxNewToolbarDialog( 0, aNewName );
+    boost::scoped_ptr<SvxNewToolbarDialog> pNameDialog(new SvxNewToolbarDialog( 0, aNewName ));
 
     sal_uInt16 nInsertPos;
     for ( sal_uInt16 i = 0 ; i < m_pSaveInListBox->GetEntryCount(); ++i )
@@ -4464,8 +4446,6 @@ IMPL_LINK( SvxToolbarConfigPage, NewToolbarHdl, Button *, pButton )
         pData->SetModified( true );
     }
 
-    delete pNameDialog;
-
     return 0;
 }
 
diff --git a/cui/source/customize/macropg.cxx b/cui/source/customize/macropg.cxx
index 20a5c2c..bd89250 100644
--- a/cui/source/customize/macropg.cxx
+++ b/cui/source/customize/macropg.cxx
@@ -45,6 +45,7 @@
 
 #include <algorithm>
 #include <set>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -643,7 +644,7 @@ long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton*
                 )
             )
     {
-        AssignComponentDialog* pAssignDlg = new AssignComponentDialog( pThis, sEventURL );
+        boost::scoped_ptr<AssignComponentDialog> pAssignDlg(new AssignComponentDialog( pThis, sEventURL ));
 
         short ret = pAssignDlg->Execute();
         if( ret )
@@ -653,7 +654,6 @@ long _SvxMacroTabPage::GenericHandler_Impl( _SvxMacroTabPage* pThis, PushButton*
             if(!pThis->bAppEvents)
                 pThis->bDocModified = true;
         }
-        delete pAssignDlg;
     }
     else if( bAssEnabled )
     {
diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx
index ffb147e..ddcdc42 100644
--- a/cui/source/dialogs/SpellDialog.cxx
+++ b/cui/source/dialogs/SpellDialog.cxx
@@ -59,6 +59,7 @@
 #include <svtools/langtab.hxx>
 #include <comphelper/anytostring.hxx>
 #include <cppuhelper/exc_hlp.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -497,8 +498,8 @@ void SpellDialog::StartSpellOptDlg_Impl()
     };
     SfxItemSet aSet( SfxGetpApp()->GetPool(), aSpellInfos);
     aSet.Put(SfxSpellCheckItem( xSpell, SID_ATTR_SPELL ));
-    SfxSingleTabDialog* pDlg =
-        new SfxSingleTabDialog(this, aSet, "SpellOptionsDialog", "cui/ui/spelloptionsdialog.ui");
+    boost::scoped_ptr<SfxSingleTabDialog> pDlg(
+        new SfxSingleTabDialog(this, aSet, "SpellOptionsDialog", "cui/ui/spelloptionsdialog.ui"));
     SfxTabPage* pPage = SvxLinguTabPage::Create( pDlg->get_content_area(), &aSet );
     ( (SvxLinguTabPage*)pPage )->HideGroups( GROUP_MODULES );
     pDlg->SetTabPage( pPage );
@@ -509,7 +510,6 @@ void SpellDialog::StartSpellOptDlg_Impl()
         if(pOutSet)
             OfaTreeOptionsDialog::ApplyLanguageOptions(*pOutSet);
     }
-    delete pDlg;
 }
 
 namespace
@@ -1459,7 +1459,7 @@ bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
                 //text has been added on the right and only the 'error attribute has to be corrected
                 if(pErrorAttrLeft)
                 {
-                    TextAttrib* pNewError =  pErrorAttrLeft->GetAttr().Clone();
+                    boost::scoped_ptr<TextAttrib> pNewError(pErrorAttrLeft->GetAttr().Clone());
                     sal_uInt16 nStart = pErrorAttrLeft->GetStart();
                     sal_uInt16 nEnd = pErrorAttrLeft->GetEnd();
                     pTextEngine->RemoveAttrib( 0, *pErrorAttrLeft );
@@ -1470,7 +1470,6 @@ bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
                         bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
                         MoveErrorMarkTo(nStart, nEnd, bGrammar);
                     }
-                    delete pNewError;
                 }
                 //text has been added on the left then the error attribute has to be expanded and the
                 //field attribute on the right - if any - has to be contracted
@@ -1479,7 +1478,7 @@ bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
                     //determine the change
                     sal_Int32 nAddedChars = GetText().getLength() - nCurrentLen;
 
-                    TextAttrib* pNewError =  pErrorAttr->GetAttr().Clone();
+                    boost::scoped_ptr<TextAttrib> pNewError(pErrorAttr->GetAttr().Clone());
                     sal_Int32 nStart = pErrorAttr->GetStart();
                     sal_Int32 nEnd = pErrorAttr->GetEnd();
                     pTextEngine->RemoveAttrib( 0, *pErrorAttr );
@@ -1491,16 +1490,15 @@ bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
                         bool bGrammar = static_cast<const SpellErrorAttrib&>(*pNewError).GetErrorDescription().bIsGrammarError;
                         MoveErrorMarkTo(nStart, nEnd, bGrammar);
                     }
-                    delete pNewError;
+                    pNewError.reset();
 
                     if(pBackAttrLeft)
                     {
-                        TextAttrib* pNewBack =  pBackAttrLeft->GetAttr().Clone();
+                        boost::scoped_ptr<TextAttrib> pNewBack(pBackAttrLeft->GetAttr().Clone());
                         sal_uInt16 _nStart = pBackAttrLeft->GetStart();
                         sal_uInt16 _nEnd = pBackAttrLeft->GetEnd();
                         pTextEngine->RemoveAttrib( 0, *pBackAttrLeft );
                         SetAttrib( *pNewBack, 0, _nStart, _nEnd - nAddedChars);
-                        delete pNewBack;
                     }
                 }
             }
@@ -1522,10 +1520,9 @@ bool SentenceEditWindow_Impl::PreNotify( NotifyEvent& rNEvt )
                     m_nErrorEnd = pFontColor->GetEnd();
                     if(pErrorAttrib->GetStart() != m_nErrorStart || pErrorAttrib->GetEnd() != m_nErrorEnd)
                     {
-                        TextAttrib* pNewError =  pErrorAttrib->GetAttr().Clone();
+                        boost::scoped_ptr<TextAttrib> pNewError(pErrorAttrib->GetAttr().Clone());
                         pTextEngine->RemoveAttrib( 0, *pErrorAttr );
                         SetAttrib( *pNewError, 0, m_nErrorStart, m_nErrorEnd );
-                        delete pNewError;
                     }
                 }
             }
@@ -1683,11 +1680,10 @@ void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Languag
     // undo expanded attributes!
     if( pBackAttrib && pBackAttrib->GetStart() < m_nErrorStart && pBackAttrib->GetEnd() == m_nErrorEnd + nDiffLen)
     {
-        TextAttrib* pNewBackground = pBackAttrib->GetAttr().Clone();
+        boost::scoped_ptr<TextAttrib> pNewBackground(pBackAttrib->GetAttr().Clone());
         sal_uInt16 nStart = pBackAttrib->GetStart();
         pTextEngine->RemoveAttrib(0, *pBackAttrib);
         pTextEngine->SetAttrib(*pNewBackground, 0, nStart, m_nErrorStart);
-        delete pNewBackground;
     }
     pTextEngine->SetModified(true);
 


More information about the Libreoffice-commits mailing list