From fb2ad7ce2d201d9d2504274ad7e1bd0e803d9902 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 18 Aug 2015 11:33:49 +0200 Subject: new loplugin automem find places where we should be using std::unique_ptr Change-Id: I5b9defe778fdc4738ecea381215396874db59e66 --- registry/source/reflread.cxx | 39 ++++++++++----------------------------- registry/source/reflwrit.cxx | 30 ++++++++++-------------------- 2 files changed, 20 insertions(+), 49 deletions(-) (limited to 'registry') diff --git a/registry/source/reflread.cxx b/registry/source/reflread.cxx index aa8d61a85db6..ef7d4e42f29c 100644 --- a/registry/source/reflread.cxx +++ b/registry/source/reflread.cxx @@ -256,16 +256,14 @@ class ConstantPool : public BlopObject { public: - sal_uInt16 m_numOfEntries; - sal_Int32* m_pIndex; // index values may be < 0 for cached string constants + sal_uInt16 m_numOfEntries; + std::unique_ptr m_pIndex; // index values may be < 0 for cached string constants - StringCache* m_pStringCache; + std::unique_ptr m_pStringCache; ConstantPool(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries) : BlopObject(buffer, len, false) , m_numOfEntries(numEntries) - , m_pIndex(NULL) - , m_pStringCache(NULL) { } @@ -292,30 +290,19 @@ public: ConstantPool::~ConstantPool() { - delete[] m_pIndex; - delete m_pStringCache; } sal_uInt32 ConstantPool::parseIndex() { - if (m_pIndex) - { - delete[] m_pIndex; - m_pIndex = NULL; - } - - if (m_pStringCache) - { - delete m_pStringCache; - m_pStringCache = NULL; - } + m_pIndex.reset(); + m_pStringCache.reset(); sal_uInt32 offset = 0; sal_uInt16 numOfStrings = 0; if (m_numOfEntries) { - m_pIndex = new sal_Int32[m_numOfEntries]; + m_pIndex.reset( new sal_Int32[m_numOfEntries] ); for (int i = 0; i < m_numOfEntries; i++) { @@ -334,7 +321,7 @@ sal_uInt32 ConstantPool::parseIndex() if (numOfStrings) { - m_pStringCache = new StringCache(numOfStrings); + m_pStringCache.reset( new StringCache(numOfStrings) ); } m_bufferLen = offset; @@ -883,13 +870,12 @@ public: sal_uInt16 m_numOfMethodEntries; sal_uInt16 m_numOfParamEntries; size_t m_PARAM_ENTRY_SIZE; - sal_uInt32* m_pIndex; + std::unique_ptr m_pIndex; ConstantPool* m_pCP; MethodList(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries, ConstantPool* pCP) : BlopObject(buffer, len, false) , m_numOfEntries(numEntries) - , m_pIndex(NULL) , m_pCP(pCP) { if ( m_numOfEntries > 0 ) @@ -926,7 +912,6 @@ private: MethodList::~MethodList() { - if (m_pIndex) delete[] m_pIndex; } sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index ) @@ -936,18 +921,14 @@ sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index ) sal_uInt32 MethodList::parseIndex() { - if (m_pIndex) - { - delete[] m_pIndex; - m_pIndex = NULL; - } + m_pIndex.reset(); sal_uInt32 offset = 0; if (m_numOfEntries) { offset = 2 * sizeof(sal_uInt16); - m_pIndex = new sal_uInt32[m_numOfEntries]; + m_pIndex.reset( new sal_uInt32[m_numOfEntries] ); for (int i = 0; i < m_numOfEntries; i++) { diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx index 689bc2daa099..be4b15cd9aea 100644 --- a/registry/source/reflwrit.cxx +++ b/registry/source/reflwrit.cxx @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -514,9 +515,9 @@ public: OString m_returnTypeName; RTMethodMode m_mode; sal_uInt16 m_paramCount; - ParamEntry* m_params; + std::unique_ptr m_params; sal_uInt16 m_excCount; - OString* m_excNames; + std::unique_ptr m_excNames; OString m_doku; MethodEntry(); @@ -540,16 +541,12 @@ protected: MethodEntry::MethodEntry() : m_mode(RTMethodMode::INVALID) , m_paramCount(0) - , m_params(NULL) , m_excCount(0) - , m_excNames(NULL) { } MethodEntry::~MethodEntry() { - delete[] m_params; - delete[] m_excNames; } void MethodEntry::setData(const OString& name, @@ -596,11 +593,11 @@ void MethodEntry::reallocParams(sal_uInt16 size) newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode); } - delete[] m_params; + m_params.reset(); } m_paramCount = size; - m_params = newParams; + m_params.reset( newParams ); } void MethodEntry::reallocExcs(sal_uInt16 size) @@ -620,10 +617,8 @@ void MethodEntry::reallocExcs(sal_uInt16 size) newExcNames[i] = m_excNames[i]; } - delete[] m_excNames; - m_excCount = size; - m_excNames = newExcNames; + m_excNames.reset( newExcNames ); } @@ -654,7 +649,7 @@ public: sal_uInt16 m_referenceCount; ReferenceEntry* m_references; - sal_uInt8* m_blop; + std::unique_ptr m_blop; sal_uInt32 m_blopSize; TypeWriter(typereg_Version version, @@ -701,7 +696,6 @@ TypeWriter::TypeWriter(typereg_Version version, , m_methods(NULL) , m_referenceCount(referenceCount) , m_references(NULL) - , m_blop(NULL) , m_blopSize(0) { if (m_nSuperTypes > 0) @@ -727,9 +721,6 @@ TypeWriter::~TypeWriter() if (m_superTypeNames) delete[] m_superTypeNames; - if (m_blop) - delete[] m_blop; - if (m_fieldCount) delete[] m_fields; @@ -1151,8 +1142,7 @@ void TypeWriter::createBlop() delete[] pBlopMethods; delete[] pBlopReferences; - delete[] m_blop; - m_blop = blop; + m_blop.reset( blop ); m_blopSize = blopSize; } @@ -1259,7 +1249,7 @@ void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * SAL_THROW_EXTERN_C() { TypeWriter * writer = static_cast< TypeWriter * >(handle); - if (writer->m_blop == 0) { + if (!writer->m_blop) { try { writer->createBlop(); } catch (std::bad_alloc &) { @@ -1267,7 +1257,7 @@ void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * } } *size = writer->m_blopSize; - return writer->m_blop; + return writer->m_blop.get(); } static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry) -- cgit