From 06951f8c14d6b8861af58bbb6b7f61a00b378a1c Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 4 Sep 2018 09:49:34 +0200 Subject: loplugin:useuniqueptr in TypeWriter::createBlop Change-Id: I33ce7786430d9a8c7cbc835fc5ca381fe5ab8b8f Reviewed-on: https://gerrit.libreoffice.org/59993 Tested-by: Jenkins Reviewed-by: Noel Grandin --- registry/source/reflwrit.cxx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx index dc3e2a15b603..c85113293308 100644 --- a/registry/source/reflwrit.cxx +++ b/registry/source/reflwrit.cxx @@ -718,9 +718,9 @@ void TypeWriter::createBlop() { //TODO: Fix memory leaks that occur when std::bad_alloc is thrown - sal_uInt8* pBlopFields = nullptr; - sal_uInt8* pBlopMethods = nullptr; - sal_uInt8* pBlopReferences = nullptr; + std::unique_ptr pBlopFields; + std::unique_ptr pBlopMethods; + std::unique_ptr pBlopReferences; sal_uInt8* pBuffer = nullptr; sal_uInt32 blopFieldsSize = 0; sal_uInt32 blopMethodsSize = 0; @@ -797,8 +797,8 @@ void TypeWriter::createBlop() blopSize += blopFieldsSize; - pBlopFields = new sal_uInt8[blopFieldsSize]; - pBuffer = pBlopFields; + pBlopFields.reset(new sal_uInt8[blopFieldsSize]); + pBuffer = pBlopFields.get(); pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES); @@ -878,11 +878,11 @@ void TypeWriter::createBlop() blopMethodsSize += pMethodEntrySize[i]; } - pBlopMethods = new sal_uInt8[blopMethodsSize]; + pBlopMethods.reset(new sal_uInt8[blopMethodsSize]); blopSize += blopMethodsSize; - pBuffer = pBlopMethods; + pBuffer = pBlopMethods.get(); pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES); pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES ); @@ -981,8 +981,8 @@ void TypeWriter::createBlop() blopSize += blopReferenceSize; - pBlopReferences = new sal_uInt8[blopReferenceSize]; - pBuffer = pBlopReferences; + pBlopReferences.reset(new sal_uInt8[blopReferenceSize]); + pBuffer = pBlopReferences.get(); pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES); @@ -1088,17 +1088,13 @@ void TypeWriter::createBlop() }; // write fields - writeList(m_fieldCount, pBlopFields, blopFieldsSize); + writeList(m_fieldCount, pBlopFields.get(), blopFieldsSize); // write methods - writeList(m_methodCount, pBlopMethods, blopMethodsSize); + writeList(m_methodCount, pBlopMethods.get(), blopMethodsSize); // write references - writeList(m_referenceCount, pBlopReferences, blopReferenceSize); - - delete[] pBlopFields; - delete[] pBlopMethods; - delete[] pBlopReferences; + writeList(m_referenceCount, pBlopReferences.get(), blopReferenceSize); m_blop.reset( blop ); m_blopSize = blopSize; -- cgit