From f38bf4c6c29d685ec4f1015be09f64c7ae2eb172 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Fri, 4 Jul 2014 00:55:08 +0900 Subject: Avoid possible memory leaks in case of exceptions Change-Id: I04a0a2c296206f155ee4916b15b853a7f10c2c2a --- svtools/source/control/calendar.cxx | 39 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'svtools/source/control/calendar.cxx') diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx index 26427a42793f..b380baf87e48 100644 --- a/svtools/source/control/calendar.cxx +++ b/svtools/source/control/calendar.cxx @@ -37,7 +37,7 @@ #include #include #include - +#include #define DAY_OFFX 4 @@ -1084,7 +1084,7 @@ void Calendar::ImplUpdateSelection( IntDateSet* pOld ) void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest, bool bMove, bool bExpand, bool bExtended ) { - IntDateSet* pOldSel = new IntDateSet( *mpSelectTable ); + boost::scoped_ptr pOldSel(new IntDateSet( *mpSelectTable )); Date aOldDate = maCurDate; Date aTempDate = rDate; @@ -1181,7 +1181,7 @@ void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest, } HideFocus(); if ( bNewSel ) - ImplUpdateSelection( pOldSel ); + ImplUpdateSelection( pOldSel.get() ); if ( !bNewSel || pOldSel->find( aOldDate.GetDate() ) == pOldSel->end() ) ImplUpdateDate( aOldDate ); // assure focus rectangle is displayed again @@ -1189,7 +1189,6 @@ void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest, || mpSelectTable->find( maCurDate.GetDate() ) == mpSelectTable->end() ) ImplUpdateDate( maCurDate ); } - delete pOldSel; } @@ -1355,18 +1354,17 @@ void Calendar::ImplEndTracking( bool bCancel ) if ( !bSpinDown ) { - IntDateSet* pOldSel = new IntDateSet( *mpSelectTable ); + boost::scoped_ptr pOldSel(new IntDateSet( *mpSelectTable )); Date aOldDate = maCurDate; maCurDate = maOldCurDate; *mpSelectTable = *mpOldSelectTable; HideFocus(); - ImplUpdateSelection( pOldSel ); + ImplUpdateSelection( pOldSel.get() ); if ( pOldSel->find( aOldDate.GetDate() ) == pOldSel->end() ) ImplUpdateDate( aOldDate ); // assure focus rectangle is displayed again if ( HasFocus() || mpSelectTable->find( maCurDate.GetDate() ) == mpSelectTable->end() ) ImplUpdateDate( maCurDate ); - delete pOldSel; } } @@ -1585,7 +1583,7 @@ void Calendar::KeyInput( const KeyEvent& rKEvt ) { if ( bMultiSel && bExpand ) { - IntDateSet* pOldSel = new IntDateSet( *mpSelectTable ); + boost::scoped_ptr pOldSel(new IntDateSet( *mpSelectTable )); Date aOldAnchorDate = maAnchorDate; mbSelLeft = aNewDate < maAnchorDate; if ( !bExtended ) @@ -1609,8 +1607,7 @@ void Calendar::KeyInput( const KeyEvent& rKEvt ) mbInSelChange = true; SelectionChanging(); mbInSelChange = false; - ImplUpdateSelection( pOldSel ); - delete pOldSel; + ImplUpdateSelection( pOldSel.get() ); } else { @@ -1824,40 +1821,30 @@ void Calendar::SelectDate( const Date& rDate, bool bSelect ) if ( !rDate.IsValidAndGregorian() ) return; - IntDateSet* pOldSel; + boost::scoped_ptr pOldSel; if ( !mbInSelChange ) - pOldSel = new IntDateSet( *mpSelectTable ); - else - pOldSel = NULL; + pOldSel.reset(new IntDateSet( *mpSelectTable )); ImplCalendarSelectDate( mpSelectTable, rDate, bSelect ); if ( pOldSel ) - { - ImplUpdateSelection( pOldSel ); - delete pOldSel; - } + ImplUpdateSelection( pOldSel.get() ); } void Calendar::SetNoSelection() { - IntDateSet* pOldSel; + boost::scoped_ptr pOldSel; if ( !mbInSelChange ) - pOldSel = new IntDateSet( *mpSelectTable ); - else - pOldSel = NULL; + pOldSel.reset(new IntDateSet( *mpSelectTable )); ImplCalendarClearSelectDate( mpSelectTable ); if ( pOldSel ) - { - ImplUpdateSelection( pOldSel ); - delete pOldSel; - } + ImplUpdateSelection( pOldSel.get() ); } -- cgit