[Libreoffice-commits] core.git: compilerplugins/clang l10ntools/inc l10ntools/source registry/source

Noel Grandin noel at peralex.com
Thu Aug 20 00:56:28 PDT 2015


 compilerplugins/clang/automem.cxx |   91 ++++++++++++++++++++++++++++++++++++++
 l10ntools/inc/cfgmerge.hxx        |    2 
 l10ntools/inc/po.hxx              |    3 -
 l10ntools/inc/xmlparse.hxx        |   17 +++----
 l10ntools/inc/xrmmerge.hxx        |    4 -
 l10ntools/source/cfgmerge.cxx     |    9 +--
 l10ntools/source/po.cxx           |   16 ++----
 l10ntools/source/xmlparse.cxx     |   67 ++++++++++-----------------
 l10ntools/source/xrmmerge.cxx     |   23 +++------
 registry/source/reflread.cxx      |   39 ++++------------
 registry/source/reflwrit.cxx      |   30 ++++--------
 11 files changed, 167 insertions(+), 134 deletions(-)

New commits:
commit fb2ad7ce2d201d9d2504274ad7e1bd0e803d9902
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Aug 18 11:33:49 2015 +0200

    new loplugin automem
    
    find places where we should be using std::unique_ptr
    
    Change-Id: I5b9defe778fdc4738ecea381215396874db59e66

diff --git a/compilerplugins/clang/automem.cxx b/compilerplugins/clang/automem.cxx
new file mode 100644
index 0000000..7981c7a
--- /dev/null
+++ b/compilerplugins/clang/automem.cxx
@@ -0,0 +1,91 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <cassert>
+#include <string>
+#include <iostream>
+#include <fstream>
+#include <set>
+#include "plugin.hxx"
+#include "compat.hxx"
+
+/**
+  Find calls to "delete x" where x is a field on an object.
+  Should rather be using std::unique_ptr
+*/
+
+namespace {
+
+class AutoMem:
+    public RecursiveASTVisitor<AutoMem>, public loplugin::Plugin
+{
+public:
+    explicit AutoMem(InstantiationData const & data): Plugin(data) {}
+
+    virtual void run() override
+    {
+        TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
+    }
+
+    bool TraverseCXXDestructorDecl(CXXDestructorDecl* );
+    bool VisitCXXDeleteExpr(const CXXDeleteExpr* );
+private:
+    bool mbInsideDestructor;
+};
+
+bool AutoMem::TraverseCXXDestructorDecl(CXXDestructorDecl* expr)
+{
+    mbInsideDestructor = true;
+    bool ret = RecursiveASTVisitor::TraverseCXXDestructorDecl(expr);
+    mbInsideDestructor = false;
+    return ret;
+}
+
+bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr)
+{
+    if (ignoreLocation( expr ))
+        return true;
+    StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(expr->getLocStart()));
+    if (aFileName.startswith(SRCDIR "/include/salhelper/")
+        || aFileName.startswith(SRCDIR "/include/osl/")
+        || aFileName.startswith(SRCDIR "/salhelper/")
+        || aFileName.startswith(SRCDIR "/store/")
+        || aFileName.startswith(SRCDIR "/sal/"))
+        return true;
+
+    if (mbInsideDestructor)
+        return true;
+
+    const ImplicitCastExpr* pCastExpr = dyn_cast<ImplicitCastExpr>(expr->getArgument());
+    if (!pCastExpr)
+        return true;
+    const MemberExpr* pMemberExpr = dyn_cast<MemberExpr>(pCastExpr->getSubExpr());
+    if (!pMemberExpr)
+        return true;
+    // ignore union games
+    const FieldDecl* pFieldDecl = dyn_cast<FieldDecl>(pMemberExpr->getMemberDecl());
+    if (!pFieldDecl)
+        return true;
+    TagDecl const * td = dyn_cast<TagDecl>(pFieldDecl->getDeclContext());
+    if (td->isUnion())
+        return true;
+
+    report(
+        DiagnosticsEngine::Warning,
+        "calling delete on object field, rather use std::unique_ptr or std::scoped_ptr",
+        expr->getLocStart())
+        << expr->getSourceRange();
+    return true;
+}
+
+loplugin::Plugin::Registration< AutoMem > X("automem", false);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/l10ntools/inc/cfgmerge.hxx b/l10ntools/inc/cfgmerge.hxx
index c61ff03..c2342b5 100644
--- a/l10ntools/inc/cfgmerge.hxx
+++ b/l10ntools/inc/cfgmerge.hxx
@@ -159,7 +159,7 @@ class CfgMerge : public CfgParser
 private:
     MergeDataFile *pMergeDataFile;
     std::vector<OString> aLanguages;
-    ResData *pResData;
+    std::unique_ptr<ResData> pResData;
 
     OString sFilename;
     bool bEnglish;
diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx
index e1a584d..830db7d 100644
--- a/l10ntools/inc/po.hxx
+++ b/l10ntools/inc/po.hxx
@@ -11,6 +11,7 @@
 #define INCLUDED_L10NTOOLS_INC_PO_HXX
 
 #include <fstream>
+#include <memory>
 #include <rtl/string.hxx>
 #include <boost/noncopyable.hpp>
 
@@ -32,7 +33,7 @@ class PoEntry
 {
 private:
 
-    GenPoEntry* m_pGenPo;
+    std::unique_ptr<GenPoEntry> m_pGenPo;
     bool m_bIsInitialized;
 
 public:
diff --git a/l10ntools/inc/xmlparse.hxx b/l10ntools/inc/xmlparse.hxx
index 69ee3f9..8b94d31 100644
--- a/l10ntools/inc/xmlparse.hxx
+++ b/l10ntools/inc/xmlparse.hxx
@@ -110,12 +110,12 @@ class XMLData;
 class XMLParentNode : public XMLChildNode
 {
 private:
-    XMLChildNodeList* m_pChildList;
+    std::unique_ptr<XMLChildNodeList> m_pChildList;
 
 protected:
     XMLParentNode( XMLParentNode *pPar )
-        : XMLChildNode( pPar ), m_pChildList( NULL ){}
-    XMLParentNode(): m_pChildList(NULL){}
+        : XMLChildNode( pPar ) {}
+    XMLParentNode() {}
 
     XMLParentNode( const XMLParentNode& );
 
@@ -124,7 +124,7 @@ protected:
 
 public:
     /// returns child list of this node
-    XMLChildNodeList *GetChildList() { return m_pChildList; }
+    XMLChildNodeList *GetChildList() { return m_pChildList.get(); }
 
     /// adds a new child
     void AddChild(
@@ -158,7 +158,7 @@ public:
     void SearchL10NElements( XMLChildNode *pCur, int pos = 0 );
     void Extract( XMLFile *pCur = NULL );
 
-    XMLHashMap* GetStrings(){ return m_pXMLStrings; }
+    XMLHashMap* GetStrings(){ return m_pXMLStrings.get(); }
     void Write( OString const &rFilename );
     bool Write( std::ofstream &rStream, XMLNode *pCur = NULL );
 
@@ -181,7 +181,7 @@ protected:
     OString m_sFileName;
 
     TagMap m_aNodes_localize;
-    XMLHashMap* m_pXMLStrings;
+    std::unique_ptr<XMLHashMap> m_pXMLStrings;
 
     std::vector <OString> m_vOrder;
 };
@@ -201,7 +201,7 @@ class XMLElement : public XMLParentNode
 {
 private:
     OString m_sElementName;
-    XMLAttributeList *m_pAttributes;
+    std::unique_ptr<XMLAttributeList> m_pAttributes;
     OString m_sProject;
     OString m_sFilename;
     OString m_sId;
@@ -230,7 +230,7 @@ public:
     OString GetName() const { return m_sElementName; }
 
     /// returns list of attributes of this element
-    XMLAttributeList *GetAttributeList() { return m_pAttributes; }
+    XMLAttributeList *GetAttributeList() { return m_pAttributes.get(); }
 
     /// adds a new attribute to this element, typically used by parser
     void AddAttribute( const OString &rAttribute, const OString &rValue );
@@ -338,7 +338,6 @@ private:
     XML_Parser m_aParser;
     XMLError m_aErrorInformation;
 
-    XMLFile *m_pXMLFile;
     XMLParentNode *m_pCurNode;
     XMLData *m_pCurData;
 
diff --git a/l10ntools/inc/xrmmerge.hxx b/l10ntools/inc/xrmmerge.hxx
index df2ddaf..c3820b4 100644
--- a/l10ntools/inc/xrmmerge.hxx
+++ b/l10ntools/inc/xrmmerge.hxx
@@ -72,7 +72,7 @@ public:
 class XRMResExport : public XRMResParser
 {
 private:
-    ResData *pResData;
+    std::unique_ptr<ResData> pResData;
     OString sPath;
     PoOfstream pOutputStream;
 protected:
@@ -105,7 +105,7 @@ class XRMResMerge : public XRMResParser
 private:
     MergeDataFile *pMergeDataFile;
     OString sFilename;
-    ResData *pResData;
+    std::unique_ptr<ResData> pResData;
     std::ofstream pOutputStream;
     std::vector<OString> aLanguages;
 
diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx
index 5093bd4..de7ccea 100644
--- a/l10ntools/source/cfgmerge.cxx
+++ b/l10ntools/source/cfgmerge.cxx
@@ -399,7 +399,6 @@ CfgMerge::CfgMerge(
     const OString &rMergeSource, const OString &rOutputFile,
     const OString &rFilename, const OString &rLanguage )
                 : pMergeDataFile( NULL ),
-                pResData( NULL ),
                 sFilename( rFilename ),
                 bEnglish( false )
 {
@@ -429,7 +428,6 @@ CfgMerge::~CfgMerge()
 {
     pOutputStream.close();
     delete pMergeDataFile;
-    delete pResData;
 }
 
 void CfgMerge::WorkOnText(OString &, const OString& rLangIndex)
@@ -447,7 +445,7 @@ void CfgMerge::WorkOnText(OString &, const OString& rLangIndex)
                 sGroupId = aStack.GetAccessPath( aStack.size() - 2 );
             }
 
-            pResData = new ResData( sGroupId, sFilename );
+            pResData.reset( new ResData( sGroupId, sFilename ) );
             pResData->sId = sLocalId;
             pResData->sResTyp = pStackData->sResTyp;
         }
@@ -466,7 +464,7 @@ void CfgMerge::WorkOnResourceEnd()
 {
 
     if ( pMergeDataFile && pResData && bLocalize && bEnglish ) {
-        MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrysCaseSensitive( pResData );
+        MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrysCaseSensitive( pResData.get() );
         if ( pEntrys ) {
             OString sCur;
 
@@ -511,8 +509,7 @@ void CfgMerge::WorkOnResourceEnd()
             }
         }
     }
-    delete pResData;
-    pResData = NULL;
+    pResData.reset();
     bEnglish = false;
 }
 
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index c2acc2e..5dfa0b7 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -224,8 +224,7 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream)
 
 
 PoEntry::PoEntry()
-    : m_pGenPo( 0 )
-    , m_bIsInitialized( false )
+    : m_bIsInitialized( false )
 {
 }
 
@@ -233,8 +232,7 @@ PoEntry::PoEntry(
     const OString& rSourceFile, const OString& rResType, const OString& rGroupId,
     const OString& rLocalId, const OString& rHelpText,
     const OString& rText, const TYPE eType )
-    : m_pGenPo( 0 )
-    , m_bIsInitialized( false )
+    : m_bIsInitialized( false )
 {
     if( rSourceFile.isEmpty() )
         throw NOSOURCFILE;
@@ -247,7 +245,7 @@ PoEntry::PoEntry(
     else if ( rHelpText.getLength() == 5 )
         throw WRONGHELPTEXT;
 
-    m_pGenPo = new GenPoEntry();
+    m_pGenPo.reset( new GenPoEntry() );
     m_pGenPo->setReference(rSourceFile.copy(rSourceFile.lastIndexOf('/')+1));
 
     OString sMsgCtxt =
@@ -273,7 +271,6 @@ PoEntry::PoEntry(
 
 PoEntry::~PoEntry()
 {
-    delete m_pGenPo;
 }
 
 PoEntry::PoEntry( const PoEntry& rPo )
@@ -296,13 +293,12 @@ PoEntry& PoEntry::operator=(const PoEntry& rPo)
         }
         else
         {
-            m_pGenPo = new GenPoEntry( *(rPo.m_pGenPo) );
+            m_pGenPo.reset( new GenPoEntry( *(rPo.m_pGenPo) ) );
         }
     }
     else
     {
-        delete m_pGenPo;
-        m_pGenPo = 0;
+        m_pGenPo.reset();
     }
     m_bIsInitialized = rPo.m_bIsInitialized;
     return *this;
@@ -594,7 +590,7 @@ void PoIfstream::readEntry( PoEntry& rPoEntry )
             }
             else
             {
-                rPoEntry.m_pGenPo = new GenPoEntry( aGenPo );
+                rPoEntry.m_pGenPo.reset( new GenPoEntry( aGenPo ) );
             }
             rPoEntry.m_bIsInitialized = true;
         }
diff --git a/l10ntools/source/xmlparse.cxx b/l10ntools/source/xmlparse.cxx
index 06fcef0..3d22920 100644
--- a/l10ntools/source/xmlparse.cxx
+++ b/l10ntools/source/xmlparse.cxx
@@ -78,17 +78,16 @@ XMLParentNode::~XMLParentNode()
 {
     if( m_pChildList )
     {
-            RemoveAndDeleteAllChildren();
-            delete m_pChildList;
+        RemoveAndDeleteAllChildren();
     }
-    m_pChildList = NULL;
 }
+
 XMLParentNode::XMLParentNode( const XMLParentNode& rObj)
 : XMLChildNode( rObj )
 {
     if( rObj.m_pChildList )
     {
-        m_pChildList=new XMLChildNodeList();
+        m_pChildList.reset( new XMLChildNodeList() );
         for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ )
         {
             XMLChildNode* pNode = (*rObj.m_pChildList)[ i ];
@@ -109,9 +108,8 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj)
             }
         }
     }
-    else
-        m_pChildList = NULL;
 }
+
 XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj)
 {
     if(this!=&rObj)
@@ -120,17 +118,15 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj)
         if( m_pChildList )
         {
             RemoveAndDeleteAllChildren();
-            delete m_pChildList;
-            m_pChildList = NULL;
         }
         if( rObj.m_pChildList )
         {
-            m_pChildList=new XMLChildNodeList();
+            m_pChildList.reset( new XMLChildNodeList() );
             for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ )
                 AddChild( (*rObj.m_pChildList)[ i ] );
         }
         else
-            m_pChildList = NULL;
+            m_pChildList.reset();
 
     }
     return *this;
@@ -138,7 +134,7 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj)
 void XMLParentNode::AddChild( XMLChildNode *pChild )
 {
     if ( !m_pChildList )
-        m_pChildList = new XMLChildNodeList();
+        m_pChildList.reset( new XMLChildNodeList() );
     m_pChildList->push_back( pChild );
 }
 
@@ -313,14 +309,12 @@ XMLFile::~XMLFile()
         {
             delete pos->second;             // Check and delete content also ?
         }
-        delete m_pXMLStrings;
-        m_pXMLStrings = NULL;
     }
 }
+
 XMLFile::XMLFile( const OString &rFileName ) // the file name, empty if created from memory stream
     : XMLParentNode( NULL )
     , m_sFileName( rFileName )
-    , m_pXMLStrings( NULL )
 {
     m_aNodes_localize.insert( TagMap::value_type(OString("bookmark") , sal_True) );
     m_aNodes_localize.insert( TagMap::value_type(OString("variable") , sal_True) );
@@ -333,9 +327,7 @@ XMLFile::XMLFile( const OString &rFileName ) // the file name, empty if created
 
 void XMLFile::Extract( XMLFile *pCur )
 {
-    delete m_pXMLStrings; // Elements ?
-
-    m_pXMLStrings = new XMLHashMap();
+    m_pXMLStrings.reset( new XMLHashMap() );
     if ( !pCur )
         SearchL10NElements( this );
     else
@@ -401,7 +393,6 @@ void XMLFile::InsertL10NElement( XMLElement* pElement )
 XMLFile::XMLFile( const XMLFile& rObj )
     : XMLParentNode( rObj )
     , m_sFileName( rObj.m_sFileName )
-    , m_pXMLStrings( 0 )
 {
     if( this != &rObj )
     {
@@ -419,11 +410,11 @@ XMLFile& XMLFile::operator=(const XMLFile& rObj)
         m_aNodes_localize = rObj.m_aNodes_localize;
         m_vOrder = rObj.m_vOrder;
 
-        delete m_pXMLStrings;
+        m_pXMLStrings.reset();
 
         if( rObj.m_pXMLStrings )
         {
-            m_pXMLStrings = new XMLHashMap();
+            m_pXMLStrings.reset( new XMLHashMap() );
             for( XMLHashMap::iterator pos = rObj.m_pXMLStrings->begin() ; pos != rObj.m_pXMLStrings->end() ; ++pos )
             {
                 LangHashMap* pElem=pos->second;
@@ -577,7 +568,6 @@ XMLElement::XMLElement(
 )
     : XMLParentNode( pParent )
     , m_sElementName( rName )
-    , m_pAttributes( NULL )
     , m_sProject(OString())
     , m_sFilename(OString())
     , m_sId(OString())
@@ -591,7 +581,6 @@ XMLElement::XMLElement(
 XMLElement::XMLElement(const XMLElement& rObj)
     : XMLParentNode( rObj )
     , m_sElementName( rObj.m_sElementName )
-    , m_pAttributes( 0 )
     , m_sProject( rObj.m_sProject )
     , m_sFilename( rObj.m_sFilename )
     , m_sId( rObj.m_sId )
@@ -602,7 +591,7 @@ XMLElement::XMLElement(const XMLElement& rObj)
 {
     if ( rObj.m_pAttributes )
     {
-        m_pAttributes = new XMLAttributeList();
+        m_pAttributes.reset( new XMLAttributeList() );
         for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ )
             AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() );
     }
@@ -626,11 +615,11 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj)
         {
             for ( size_t i = 0; i < m_pAttributes->size(); i++ )
                 delete (*m_pAttributes)[ i ];
-            delete m_pAttributes;
+            m_pAttributes.reset();
         }
         if ( rObj.m_pAttributes )
         {
-            m_pAttributes = new XMLAttributeList();
+            m_pAttributes.reset( new XMLAttributeList() );
             for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ )
                 AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() );
         }
@@ -641,7 +630,7 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj)
 void XMLElement::AddAttribute( const OString &rAttribute, const OString &rValue )
 {
     if ( !m_pAttributes )
-        m_pAttributes = new XMLAttributeList();
+        m_pAttributes.reset( new XMLAttributeList() );
     m_pAttributes->push_back( new XMLAttribute( rAttribute, rValue ) );
 }
 
@@ -682,9 +671,6 @@ XMLElement::~XMLElement()
     {
         for ( size_t i = 0; i < m_pAttributes->size(); i++ )
             delete (*m_pAttributes)[ i ];
-
-        delete m_pAttributes;
-        m_pAttributes = NULL;
     }
 }
 
@@ -817,8 +803,7 @@ static OUString lcl_pathnameToAbsoluteUrl(const OString& rPathname)
 
 
 SimpleXMLParser::SimpleXMLParser()
-    : m_pXMLFile(NULL)
-    , m_pCurNode(NULL)
+    : m_pCurNode(NULL)
     , m_pCurData(NULL)
 {
     m_aParser = XML_ParserCreate( NULL );
@@ -942,18 +927,18 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
         return 0;
     }
 
-    m_pXMLFile = pXMLFileIn;
-    m_pXMLFile->SetName( rFileName );
+    XMLFile* pXMLFile = pXMLFileIn;
+    pXMLFile->SetName( rFileName );
 
-    m_pCurNode = m_pXMLFile;
+    m_pCurNode = pXMLFile;
     m_pCurData = NULL;
 
     m_aErrorInformation.m_eCode = XML_ERROR_NONE;
     m_aErrorInformation.m_nLine = 0;
     m_aErrorInformation.m_nColumn = 0;
-    if ( !m_pXMLFile->GetName().isEmpty())
+    if ( !pXMLFile->GetName().isEmpty())
     {
-        m_aErrorInformation.m_sMessage = "File " + m_pXMLFile->GetName() + " parsed successfully";
+        m_aErrorInformation.m_sMessage = "File " + pXMLFile->GetName() + " parsed successfully";
     }
     else
         m_aErrorInformation.m_sMessage = "XML-File parsed successfully";
@@ -965,8 +950,8 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
         m_aErrorInformation.m_nColumn = XML_GetErrorColumnNumber( m_aParser );
 
         m_aErrorInformation.m_sMessage = "ERROR: ";
-        if ( !m_pXMLFile->GetName().isEmpty())
-            m_aErrorInformation.m_sMessage += m_pXMLFile->GetName();
+        if ( !pXMLFile->GetName().isEmpty())
+            m_aErrorInformation.m_sMessage += pXMLFile->GetName();
         else
             m_aErrorInformation.m_sMessage += OString( "XML-File (");
 
@@ -1047,14 +1032,14 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
         default:
             break;
         }
-        delete m_pXMLFile;
-        m_pXMLFile = NULL;
+        delete pXMLFile;
+        pXMLFile = NULL;
     }
 
     osl_unmapMappedFile(h, p, s);
     osl_closeFile(h);
 
-    return m_pXMLFile;
+    return pXMLFile;
 }
 
 namespace
diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx
index a0f5b7d..480ec29 100644
--- a/l10ntools/source/xrmmerge.cxx
+++ b/l10ntools/source/xrmmerge.cxx
@@ -296,7 +296,6 @@ void XRMResParser::Error( const OString &rError )
 XRMResExport::XRMResExport(
     const OString &rOutputFile, const OString &rFilePath )
                 : XRMResParser(),
-                pResData( NULL ),
                 sPath( rFilePath )
 {
     pOutputStream.open( rOutputFile, PoOfstream::APP );
@@ -311,7 +310,6 @@ XRMResExport::XRMResExport(
 XRMResExport::~XRMResExport()
 {
     pOutputStream.close();
-    delete pResData;
 }
 
 void XRMResExport::Output( const OString& ) {}
@@ -345,7 +343,7 @@ void XRMResExport::WorkOnText(
 
     if ( !pResData )
     {
-        pResData = new ResData( GetGID() );
+        pResData.reset( new ResData( GetGID() ) );
     }
     pResData->sText[sLang] = rText;
 }
@@ -363,8 +361,7 @@ void XRMResExport::EndOfText(
                 "Xrmex", pOutputStream, sPath, sResourceType,
                 pResData->sGId, OString(), OString(), sAct );
     }
-    delete pResData;
-    pResData = NULL;
+    pResData.reset();
 }
 
 
@@ -376,8 +373,7 @@ XRMResMerge::XRMResMerge(
     const OString &rFilename )
                 : XRMResParser(),
                 pMergeDataFile( NULL ),
-                sFilename( rFilename ) ,
-                pResData( NULL )
+                sFilename( rFilename )
 {
     if (!rMergeSource.isEmpty() && sLanguage.equalsIgnoreAsciiCase("ALL"))
     {
@@ -400,7 +396,6 @@ XRMResMerge::~XRMResMerge()
 {
     pOutputStream.close();
     delete pMergeDataFile;
-    delete pResData;
 }
 
 void XRMResMerge::WorkOnDesc(
@@ -409,7 +404,7 @@ void XRMResMerge::WorkOnDesc(
 {
     WorkOnText( rOpenTag, rText);
     if ( pMergeDataFile && pResData ) {
-        MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData );
+        MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData.get() );
         if ( pEntrys ) {
             OString sCur;
             OString sDescFilename = GetAttribute ( rOpenTag, "xlink:href" );
@@ -470,8 +465,7 @@ void XRMResMerge::WorkOnDesc(
             }
         }
     }
-    delete pResData;
-    pResData = NULL;
+    pResData.reset();
 }
 
 void XRMResMerge::WorkOnText(
@@ -480,7 +474,7 @@ void XRMResMerge::WorkOnText(
 {
     if ( pMergeDataFile ) {
         if ( !pResData ) {
-            pResData = new ResData( GetGID(), sFilename );
+            pResData.reset( new ResData( GetGID(), sFilename ) );
             pResData->sResTyp = sResourceType;
         }
     }
@@ -499,7 +493,7 @@ void XRMResMerge::EndOfText(
 
     Output( rCloseTag );
     if ( pMergeDataFile && pResData ) {
-        MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData );
+        MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData.get() );
         if ( pEntrys ) {
             OString sCur;
             for( size_t n = 0; n < aLanguages.size(); n++ ){
@@ -532,8 +526,7 @@ void XRMResMerge::EndOfText(
             }
         }
     }
-    delete pResData;
-    pResData = NULL;
+    pResData.reset();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/registry/source/reflread.cxx b/registry/source/reflread.cxx
index aa8d61a..ef7d4e42 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<sal_Int32[]> m_pIndex;           // index values may be < 0 for cached string constants
 
-    StringCache* m_pStringCache;
+    std::unique_ptr<StringCache> 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<sal_uInt32[]>  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 689bc2d..be4b15c 100644
--- a/registry/source/reflwrit.cxx
+++ b/registry/source/reflwrit.cxx
@@ -19,6 +19,7 @@
 
 
 #include <new>
+#include <memory>
 #include <sal/types.h>
 #include <sal/macros.h>
 #include <osl/endian.h>
@@ -514,9 +515,9 @@ public:
     OString         m_returnTypeName;
     RTMethodMode    m_mode;
     sal_uInt16      m_paramCount;
-    ParamEntry*     m_params;
+    std::unique_ptr<ParamEntry[]> m_params;
     sal_uInt16      m_excCount;
-    OString*        m_excNames;
+    std::unique_ptr<OString[]>    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<sal_uInt8[]> 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)


More information about the Libreoffice-commits mailing list