summaryrefslogtreecommitdiff
path: root/sc/source/core/data/documen8.cxx
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-02-12 11:23:26 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-02-12 12:33:00 -0500
commit0585322e70d3c0f1d26d6bd9c04a388a1ff55abf (patch)
treebd206df6f4f80ab4ea461137deccb6887dc72777 /sc/source/core/data/documen8.cxx
parent117b3a13b82aaac0977fd17ee5b7b63204e659f4 (diff)
Go through all ScEditCell instantiations and fix memory leaks.
Changed the signature of the constructor (one that clones the text object) to take a reference instead of a pointer, to smoke out the callers that use this constructor. Went through all its callers and made changes to either 1) pass ownership to the cell instance (if the text object uses the SfxItemPool instance returned from ScDocument::GetEditPool()), or 2) pass as const reference to make it clear that the instance will get cloned. Change-Id: I669e066d4739536bf8d3b356186503dcdfa303b0
Diffstat (limited to 'sc/source/core/data/documen8.cxx')
-rw-r--r--sc/source/core/data/documen8.cxx21
1 files changed, 11 insertions, 10 deletions
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 134fdf31d9c0..2c9d62888298 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -86,6 +86,8 @@
#include "docuno.hxx"
#include "scresid.hxx"
+#include <memory>
+
#define GET_SCALEVALUE(set,id) ((const SfxUInt16Item&)(set.Get( id ))).GetValue()
// states for online spelling in the visible range (0 is set initially)
@@ -739,14 +741,15 @@ bool ScDocument::OnlineSpellInRange( const ScRange& rSpellRange, ScAddress& rSpe
if ( bNeedEdit )
{
- EditTextObject* pNewData = pEngine->CreateTextObject();
+ SAL_WNODEPRECATED_DECLARATIONS_PUSH
+ std::auto_ptr<EditTextObject> pNewData(pEngine->CreateTextObject());
+ SAL_WNODEPRECATED_DECLARATIONS_POP
if ( eType == CELLTYPE_EDIT )
- ((ScEditCell*)pCell)->SetData( pNewData,
- pEngine->GetEditTextObjectPool() );
+ // SetData will create a clone of pNewData and stores the clone.
+ static_cast<ScEditCell*>(pCell)->SetData(pNewData.get(), pEngine->GetEditTextObjectPool());
else
- PutCell( nCol, nRow, nTab, new ScEditCell( pNewData,
- this, pEngine->GetEditTextObjectPool() ) );
- delete pNewData;
+ // The cell will take ownership of pNewData.
+ PutCell(nCol, nRow, nTab, new ScEditCell(pNewData.release(), this));
}
else // einfacher String
PutCell( nCol, nRow, nTab, new ScStringCell( pEngine->GetText() ) );
@@ -1582,10 +1585,8 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
SfxItemSet* pEmpty = new SfxItemSet( pEngine->GetEmptyItemSet() );
pEngine->SetDefaults( pEmpty, true );
- EditTextObject* pNewData = pEngine->CreateTextObject();
- PutCell( nCol, nRow, nTab,
- new ScEditCell( pNewData, this, pEngine->GetEditTextObjectPool() ) );
- delete pNewData;
+ // The cell will take ownership of the text object instance.
+ PutCell(nCol, nRow, nTab, new ScEditCell(pEngine->CreateTextObject(), this));
}
else
{