Kaydet (Commit) fb2ad7ce authored tarafından Noel Grandin's avatar Noel Grandin

new loplugin automem

find places where we should be using std::unique_ptr

Change-Id: I5b9defe778fdc4738ecea381215396874db59e66
üst af6daec7
/* -*- 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: */
...@@ -159,7 +159,7 @@ class CfgMerge : public CfgParser ...@@ -159,7 +159,7 @@ class CfgMerge : public CfgParser
private: private:
MergeDataFile *pMergeDataFile; MergeDataFile *pMergeDataFile;
std::vector<OString> aLanguages; std::vector<OString> aLanguages;
ResData *pResData; std::unique_ptr<ResData> pResData;
OString sFilename; OString sFilename;
bool bEnglish; bool bEnglish;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define INCLUDED_L10NTOOLS_INC_PO_HXX #define INCLUDED_L10NTOOLS_INC_PO_HXX
#include <fstream> #include <fstream>
#include <memory>
#include <rtl/string.hxx> #include <rtl/string.hxx>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
...@@ -32,7 +33,7 @@ class PoEntry ...@@ -32,7 +33,7 @@ class PoEntry
{ {
private: private:
GenPoEntry* m_pGenPo; std::unique_ptr<GenPoEntry> m_pGenPo;
bool m_bIsInitialized; bool m_bIsInitialized;
public: public:
......
...@@ -110,12 +110,12 @@ class XMLData; ...@@ -110,12 +110,12 @@ class XMLData;
class XMLParentNode : public XMLChildNode class XMLParentNode : public XMLChildNode
{ {
private: private:
XMLChildNodeList* m_pChildList; std::unique_ptr<XMLChildNodeList> m_pChildList;
protected: protected:
XMLParentNode( XMLParentNode *pPar ) XMLParentNode( XMLParentNode *pPar )
: XMLChildNode( pPar ), m_pChildList( NULL ){} : XMLChildNode( pPar ) {}
XMLParentNode(): m_pChildList(NULL){} XMLParentNode() {}
XMLParentNode( const XMLParentNode& ); XMLParentNode( const XMLParentNode& );
...@@ -124,7 +124,7 @@ protected: ...@@ -124,7 +124,7 @@ protected:
public: public:
/// returns child list of this node /// returns child list of this node
XMLChildNodeList *GetChildList() { return m_pChildList; } XMLChildNodeList *GetChildList() { return m_pChildList.get(); }
/// adds a new child /// adds a new child
void AddChild( void AddChild(
...@@ -158,7 +158,7 @@ public: ...@@ -158,7 +158,7 @@ public:
void SearchL10NElements( XMLChildNode *pCur, int pos = 0 ); void SearchL10NElements( XMLChildNode *pCur, int pos = 0 );
void Extract( XMLFile *pCur = NULL ); void Extract( XMLFile *pCur = NULL );
XMLHashMap* GetStrings(){ return m_pXMLStrings; } XMLHashMap* GetStrings(){ return m_pXMLStrings.get(); }
void Write( OString const &rFilename ); void Write( OString const &rFilename );
bool Write( std::ofstream &rStream, XMLNode *pCur = NULL ); bool Write( std::ofstream &rStream, XMLNode *pCur = NULL );
...@@ -181,7 +181,7 @@ protected: ...@@ -181,7 +181,7 @@ protected:
OString m_sFileName; OString m_sFileName;
TagMap m_aNodes_localize; TagMap m_aNodes_localize;
XMLHashMap* m_pXMLStrings; std::unique_ptr<XMLHashMap> m_pXMLStrings;
std::vector <OString> m_vOrder; std::vector <OString> m_vOrder;
}; };
...@@ -201,7 +201,7 @@ class XMLElement : public XMLParentNode ...@@ -201,7 +201,7 @@ class XMLElement : public XMLParentNode
{ {
private: private:
OString m_sElementName; OString m_sElementName;
XMLAttributeList *m_pAttributes; std::unique_ptr<XMLAttributeList> m_pAttributes;
OString m_sProject; OString m_sProject;
OString m_sFilename; OString m_sFilename;
OString m_sId; OString m_sId;
...@@ -230,7 +230,7 @@ public: ...@@ -230,7 +230,7 @@ public:
OString GetName() const { return m_sElementName; } OString GetName() const { return m_sElementName; }
/// returns list of attributes of this element /// 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 /// adds a new attribute to this element, typically used by parser
void AddAttribute( const OString &rAttribute, const OString &rValue ); void AddAttribute( const OString &rAttribute, const OString &rValue );
...@@ -338,7 +338,6 @@ private: ...@@ -338,7 +338,6 @@ private:
XML_Parser m_aParser; XML_Parser m_aParser;
XMLError m_aErrorInformation; XMLError m_aErrorInformation;
XMLFile *m_pXMLFile;
XMLParentNode *m_pCurNode; XMLParentNode *m_pCurNode;
XMLData *m_pCurData; XMLData *m_pCurData;
......
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
class XRMResExport : public XRMResParser class XRMResExport : public XRMResParser
{ {
private: private:
ResData *pResData; std::unique_ptr<ResData> pResData;
OString sPath; OString sPath;
PoOfstream pOutputStream; PoOfstream pOutputStream;
protected: protected:
...@@ -105,7 +105,7 @@ class XRMResMerge : public XRMResParser ...@@ -105,7 +105,7 @@ class XRMResMerge : public XRMResParser
private: private:
MergeDataFile *pMergeDataFile; MergeDataFile *pMergeDataFile;
OString sFilename; OString sFilename;
ResData *pResData; std::unique_ptr<ResData> pResData;
std::ofstream pOutputStream; std::ofstream pOutputStream;
std::vector<OString> aLanguages; std::vector<OString> aLanguages;
......
...@@ -399,7 +399,6 @@ CfgMerge::CfgMerge( ...@@ -399,7 +399,6 @@ CfgMerge::CfgMerge(
const OString &rMergeSource, const OString &rOutputFile, const OString &rMergeSource, const OString &rOutputFile,
const OString &rFilename, const OString &rLanguage ) const OString &rFilename, const OString &rLanguage )
: pMergeDataFile( NULL ), : pMergeDataFile( NULL ),
pResData( NULL ),
sFilename( rFilename ), sFilename( rFilename ),
bEnglish( false ) bEnglish( false )
{ {
...@@ -429,7 +428,6 @@ CfgMerge::~CfgMerge() ...@@ -429,7 +428,6 @@ CfgMerge::~CfgMerge()
{ {
pOutputStream.close(); pOutputStream.close();
delete pMergeDataFile; delete pMergeDataFile;
delete pResData;
} }
void CfgMerge::WorkOnText(OString &, const OString& rLangIndex) void CfgMerge::WorkOnText(OString &, const OString& rLangIndex)
...@@ -447,7 +445,7 @@ void CfgMerge::WorkOnText(OString &, const OString& rLangIndex) ...@@ -447,7 +445,7 @@ void CfgMerge::WorkOnText(OString &, const OString& rLangIndex)
sGroupId = aStack.GetAccessPath( aStack.size() - 2 ); sGroupId = aStack.GetAccessPath( aStack.size() - 2 );
} }
pResData = new ResData( sGroupId, sFilename ); pResData.reset( new ResData( sGroupId, sFilename ) );
pResData->sId = sLocalId; pResData->sId = sLocalId;
pResData->sResTyp = pStackData->sResTyp; pResData->sResTyp = pStackData->sResTyp;
} }
...@@ -466,7 +464,7 @@ void CfgMerge::WorkOnResourceEnd() ...@@ -466,7 +464,7 @@ void CfgMerge::WorkOnResourceEnd()
{ {
if ( pMergeDataFile && pResData && bLocalize && bEnglish ) { if ( pMergeDataFile && pResData && bLocalize && bEnglish ) {
MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrysCaseSensitive( pResData ); MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrysCaseSensitive( pResData.get() );
if ( pEntrys ) { if ( pEntrys ) {
OString sCur; OString sCur;
...@@ -511,8 +509,7 @@ void CfgMerge::WorkOnResourceEnd() ...@@ -511,8 +509,7 @@ void CfgMerge::WorkOnResourceEnd()
} }
} }
} }
delete pResData; pResData.reset();
pResData = NULL;
bEnglish = false; bEnglish = false;
} }
......
...@@ -224,8 +224,7 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) ...@@ -224,8 +224,7 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream)
PoEntry::PoEntry() PoEntry::PoEntry()
: m_pGenPo( 0 ) : m_bIsInitialized( false )
, m_bIsInitialized( false )
{ {
} }
...@@ -233,8 +232,7 @@ PoEntry::PoEntry( ...@@ -233,8 +232,7 @@ PoEntry::PoEntry(
const OString& rSourceFile, const OString& rResType, const OString& rGroupId, const OString& rSourceFile, const OString& rResType, const OString& rGroupId,
const OString& rLocalId, const OString& rHelpText, const OString& rLocalId, const OString& rHelpText,
const OString& rText, const TYPE eType ) const OString& rText, const TYPE eType )
: m_pGenPo( 0 ) : m_bIsInitialized( false )
, m_bIsInitialized( false )
{ {
if( rSourceFile.isEmpty() ) if( rSourceFile.isEmpty() )
throw NOSOURCFILE; throw NOSOURCFILE;
...@@ -247,7 +245,7 @@ PoEntry::PoEntry( ...@@ -247,7 +245,7 @@ PoEntry::PoEntry(
else if ( rHelpText.getLength() == 5 ) else if ( rHelpText.getLength() == 5 )
throw WRONGHELPTEXT; throw WRONGHELPTEXT;
m_pGenPo = new GenPoEntry(); m_pGenPo.reset( new GenPoEntry() );
m_pGenPo->setReference(rSourceFile.copy(rSourceFile.lastIndexOf('/')+1)); m_pGenPo->setReference(rSourceFile.copy(rSourceFile.lastIndexOf('/')+1));
OString sMsgCtxt = OString sMsgCtxt =
...@@ -273,7 +271,6 @@ PoEntry::PoEntry( ...@@ -273,7 +271,6 @@ PoEntry::PoEntry(
PoEntry::~PoEntry() PoEntry::~PoEntry()
{ {
delete m_pGenPo;
} }
PoEntry::PoEntry( const PoEntry& rPo ) PoEntry::PoEntry( const PoEntry& rPo )
...@@ -296,13 +293,12 @@ PoEntry& PoEntry::operator=(const PoEntry& rPo) ...@@ -296,13 +293,12 @@ PoEntry& PoEntry::operator=(const PoEntry& rPo)
} }
else else
{ {
m_pGenPo = new GenPoEntry( *(rPo.m_pGenPo) ); m_pGenPo.reset( new GenPoEntry( *(rPo.m_pGenPo) ) );
} }
} }
else else
{ {
delete m_pGenPo; m_pGenPo.reset();
m_pGenPo = 0;
} }
m_bIsInitialized = rPo.m_bIsInitialized; m_bIsInitialized = rPo.m_bIsInitialized;
return *this; return *this;
...@@ -594,7 +590,7 @@ void PoIfstream::readEntry( PoEntry& rPoEntry ) ...@@ -594,7 +590,7 @@ void PoIfstream::readEntry( PoEntry& rPoEntry )
} }
else else
{ {
rPoEntry.m_pGenPo = new GenPoEntry( aGenPo ); rPoEntry.m_pGenPo.reset( new GenPoEntry( aGenPo ) );
} }
rPoEntry.m_bIsInitialized = true; rPoEntry.m_bIsInitialized = true;
} }
......
...@@ -78,17 +78,16 @@ XMLParentNode::~XMLParentNode() ...@@ -78,17 +78,16 @@ XMLParentNode::~XMLParentNode()
{ {
if( m_pChildList ) if( m_pChildList )
{ {
RemoveAndDeleteAllChildren(); RemoveAndDeleteAllChildren();
delete m_pChildList;
} }
m_pChildList = NULL;
} }
XMLParentNode::XMLParentNode( const XMLParentNode& rObj) XMLParentNode::XMLParentNode( const XMLParentNode& rObj)
: XMLChildNode( rObj ) : XMLChildNode( rObj )
{ {
if( rObj.m_pChildList ) if( rObj.m_pChildList )
{ {
m_pChildList=new XMLChildNodeList(); m_pChildList.reset( new XMLChildNodeList() );
for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ ) for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ )
{ {
XMLChildNode* pNode = (*rObj.m_pChildList)[ i ]; XMLChildNode* pNode = (*rObj.m_pChildList)[ i ];
...@@ -109,9 +108,8 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj) ...@@ -109,9 +108,8 @@ XMLParentNode::XMLParentNode( const XMLParentNode& rObj)
} }
} }
} }
else
m_pChildList = NULL;
} }
XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj) XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj)
{ {
if(this!=&rObj) if(this!=&rObj)
...@@ -120,17 +118,15 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj) ...@@ -120,17 +118,15 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj)
if( m_pChildList ) if( m_pChildList )
{ {
RemoveAndDeleteAllChildren(); RemoveAndDeleteAllChildren();
delete m_pChildList;
m_pChildList = NULL;
} }
if( rObj.m_pChildList ) if( rObj.m_pChildList )
{ {
m_pChildList=new XMLChildNodeList(); m_pChildList.reset( new XMLChildNodeList() );
for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ ) for ( size_t i = 0; i < rObj.m_pChildList->size(); i++ )
AddChild( (*rObj.m_pChildList)[ i ] ); AddChild( (*rObj.m_pChildList)[ i ] );
} }
else else
m_pChildList = NULL; m_pChildList.reset();
} }
return *this; return *this;
...@@ -138,7 +134,7 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj) ...@@ -138,7 +134,7 @@ XMLParentNode& XMLParentNode::operator=(const XMLParentNode& rObj)
void XMLParentNode::AddChild( XMLChildNode *pChild ) void XMLParentNode::AddChild( XMLChildNode *pChild )
{ {
if ( !m_pChildList ) if ( !m_pChildList )
m_pChildList = new XMLChildNodeList(); m_pChildList.reset( new XMLChildNodeList() );
m_pChildList->push_back( pChild ); m_pChildList->push_back( pChild );
} }
...@@ -313,14 +309,12 @@ XMLFile::~XMLFile() ...@@ -313,14 +309,12 @@ XMLFile::~XMLFile()
{ {
delete pos->second; // Check and delete content also ? 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 XMLFile::XMLFile( const OString &rFileName ) // the file name, empty if created from memory stream
: XMLParentNode( NULL ) : XMLParentNode( NULL )
, m_sFileName( rFileName ) , 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("bookmark") , sal_True) );
m_aNodes_localize.insert( TagMap::value_type(OString("variable") , 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 ...@@ -333,9 +327,7 @@ XMLFile::XMLFile( const OString &rFileName ) // the file name, empty if created
void XMLFile::Extract( XMLFile *pCur ) void XMLFile::Extract( XMLFile *pCur )
{ {
delete m_pXMLStrings; // Elements ? m_pXMLStrings.reset( new XMLHashMap() );
m_pXMLStrings = new XMLHashMap();
if ( !pCur ) if ( !pCur )
SearchL10NElements( this ); SearchL10NElements( this );
else else
...@@ -401,7 +393,6 @@ void XMLFile::InsertL10NElement( XMLElement* pElement ) ...@@ -401,7 +393,6 @@ void XMLFile::InsertL10NElement( XMLElement* pElement )
XMLFile::XMLFile( const XMLFile& rObj ) XMLFile::XMLFile( const XMLFile& rObj )
: XMLParentNode( rObj ) : XMLParentNode( rObj )
, m_sFileName( rObj.m_sFileName ) , m_sFileName( rObj.m_sFileName )
, m_pXMLStrings( 0 )
{ {
if( this != &rObj ) if( this != &rObj )
{ {
...@@ -419,11 +410,11 @@ XMLFile& XMLFile::operator=(const XMLFile& rObj) ...@@ -419,11 +410,11 @@ XMLFile& XMLFile::operator=(const XMLFile& rObj)
m_aNodes_localize = rObj.m_aNodes_localize; m_aNodes_localize = rObj.m_aNodes_localize;
m_vOrder = rObj.m_vOrder; m_vOrder = rObj.m_vOrder;
delete m_pXMLStrings; m_pXMLStrings.reset();
if( rObj.m_pXMLStrings ) 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 ) for( XMLHashMap::iterator pos = rObj.m_pXMLStrings->begin() ; pos != rObj.m_pXMLStrings->end() ; ++pos )
{ {
LangHashMap* pElem=pos->second; LangHashMap* pElem=pos->second;
...@@ -577,7 +568,6 @@ XMLElement::XMLElement( ...@@ -577,7 +568,6 @@ XMLElement::XMLElement(
) )
: XMLParentNode( pParent ) : XMLParentNode( pParent )
, m_sElementName( rName ) , m_sElementName( rName )
, m_pAttributes( NULL )
, m_sProject(OString()) , m_sProject(OString())
, m_sFilename(OString()) , m_sFilename(OString())
, m_sId(OString()) , m_sId(OString())
...@@ -591,7 +581,6 @@ XMLElement::XMLElement( ...@@ -591,7 +581,6 @@ XMLElement::XMLElement(
XMLElement::XMLElement(const XMLElement& rObj) XMLElement::XMLElement(const XMLElement& rObj)
: XMLParentNode( rObj ) : XMLParentNode( rObj )
, m_sElementName( rObj.m_sElementName ) , m_sElementName( rObj.m_sElementName )
, m_pAttributes( 0 )
, m_sProject( rObj.m_sProject ) , m_sProject( rObj.m_sProject )
, m_sFilename( rObj.m_sFilename ) , m_sFilename( rObj.m_sFilename )
, m_sId( rObj.m_sId ) , m_sId( rObj.m_sId )
...@@ -602,7 +591,7 @@ XMLElement::XMLElement(const XMLElement& rObj) ...@@ -602,7 +591,7 @@ XMLElement::XMLElement(const XMLElement& rObj)
{ {
if ( rObj.m_pAttributes ) if ( rObj.m_pAttributes )
{ {
m_pAttributes = new XMLAttributeList(); m_pAttributes.reset( new XMLAttributeList() );
for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ ) for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ )
AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() ); AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() );
} }
...@@ -626,11 +615,11 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj) ...@@ -626,11 +615,11 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj)
{ {
for ( size_t i = 0; i < m_pAttributes->size(); i++ ) for ( size_t i = 0; i < m_pAttributes->size(); i++ )
delete (*m_pAttributes)[ i ]; delete (*m_pAttributes)[ i ];
delete m_pAttributes; m_pAttributes.reset();
} }
if ( rObj.m_pAttributes ) if ( rObj.m_pAttributes )
{ {
m_pAttributes = new XMLAttributeList(); m_pAttributes.reset( new XMLAttributeList() );
for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ ) for ( size_t i = 0; i < rObj.m_pAttributes->size(); i++ )
AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() ); AddAttribute( (*rObj.m_pAttributes)[ i ]->GetName(), (*rObj.m_pAttributes)[ i ]->GetValue() );
} }
...@@ -641,7 +630,7 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj) ...@@ -641,7 +630,7 @@ XMLElement& XMLElement::operator=(const XMLElement& rObj)
void XMLElement::AddAttribute( const OString &rAttribute, const OString &rValue ) void XMLElement::AddAttribute( const OString &rAttribute, const OString &rValue )
{ {
if ( !m_pAttributes ) if ( !m_pAttributes )
m_pAttributes = new XMLAttributeList(); m_pAttributes.reset( new XMLAttributeList() );
m_pAttributes->push_back( new XMLAttribute( rAttribute, rValue ) ); m_pAttributes->push_back( new XMLAttribute( rAttribute, rValue ) );
} }
...@@ -682,9 +671,6 @@ XMLElement::~XMLElement() ...@@ -682,9 +671,6 @@ XMLElement::~XMLElement()
{ {
for ( size_t i = 0; i < m_pAttributes->size(); i++ ) for ( size_t i = 0; i < m_pAttributes->size(); i++ )
delete (*m_pAttributes)[ i ]; delete (*m_pAttributes)[ i ];
delete m_pAttributes;
m_pAttributes = NULL;
} }
} }
...@@ -817,8 +803,7 @@ static OUString lcl_pathnameToAbsoluteUrl(const OString& rPathname) ...@@ -817,8 +803,7 @@ static OUString lcl_pathnameToAbsoluteUrl(const OString& rPathname)
SimpleXMLParser::SimpleXMLParser() SimpleXMLParser::SimpleXMLParser()
: m_pXMLFile(NULL) : m_pCurNode(NULL)
, m_pCurNode(NULL)
, m_pCurData(NULL) , m_pCurData(NULL)
{ {
m_aParser = XML_ParserCreate( NULL ); m_aParser = XML_ParserCreate( NULL );
...@@ -942,18 +927,18 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -942,18 +927,18 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
return 0; return 0;
} }
m_pXMLFile = pXMLFileIn; XMLFile* pXMLFile = pXMLFileIn;
m_pXMLFile->SetName( rFileName ); pXMLFile->SetName( rFileName );
m_pCurNode = m_pXMLFile; m_pCurNode = pXMLFile;
m_pCurData = NULL; m_pCurData = NULL;
m_aErrorInformation.m_eCode = XML_ERROR_NONE; m_aErrorInformation.m_eCode = XML_ERROR_NONE;
m_aErrorInformation.m_nLine = 0; m_aErrorInformation.m_nLine = 0;
m_aErrorInformation.m_nColumn = 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 else
m_aErrorInformation.m_sMessage = "XML-File parsed successfully"; m_aErrorInformation.m_sMessage = "XML-File parsed successfully";
...@@ -965,8 +950,8 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -965,8 +950,8 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
m_aErrorInformation.m_nColumn = XML_GetErrorColumnNumber( m_aParser ); m_aErrorInformation.m_nColumn = XML_GetErrorColumnNumber( m_aParser );
m_aErrorInformation.m_sMessage = "ERROR: "; m_aErrorInformation.m_sMessage = "ERROR: ";
if ( !m_pXMLFile->GetName().isEmpty()) if ( !pXMLFile->GetName().isEmpty())
m_aErrorInformation.m_sMessage += m_pXMLFile->GetName(); m_aErrorInformation.m_sMessage += pXMLFile->GetName();
else else
m_aErrorInformation.m_sMessage += OString( "XML-File ("); m_aErrorInformation.m_sMessage += OString( "XML-File (");
...@@ -1047,14 +1032,14 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn ...@@ -1047,14 +1032,14 @@ XMLFile *SimpleXMLParser::Execute( const OString &rFileName, XMLFile* pXMLFileIn
default: default:
break; break;
} }
delete m_pXMLFile; delete pXMLFile;
m_pXMLFile = NULL; pXMLFile = NULL;
} }
osl_unmapMappedFile(h, p, s); osl_unmapMappedFile(h, p, s);
osl_closeFile(h); osl_closeFile(h);
return m_pXMLFile; return pXMLFile;
} }
namespace namespace
......
...@@ -296,7 +296,6 @@ void XRMResParser::Error( const OString &rError ) ...@@ -296,7 +296,6 @@ void XRMResParser::Error( const OString &rError )
XRMResExport::XRMResExport( XRMResExport::XRMResExport(
const OString &rOutputFile, const OString &rFilePath ) const OString &rOutputFile, const OString &rFilePath )
: XRMResParser(), : XRMResParser(),
pResData( NULL ),
sPath( rFilePath ) sPath( rFilePath )
{ {
pOutputStream.open( rOutputFile, PoOfstream::APP ); pOutputStream.open( rOutputFile, PoOfstream::APP );
...@@ -311,7 +310,6 @@ XRMResExport::XRMResExport( ...@@ -311,7 +310,6 @@ XRMResExport::XRMResExport(
XRMResExport::~XRMResExport() XRMResExport::~XRMResExport()
{ {
pOutputStream.close(); pOutputStream.close();
delete pResData;
} }
void XRMResExport::Output( const OString& ) {} void XRMResExport::Output( const OString& ) {}
...@@ -345,7 +343,7 @@ void XRMResExport::WorkOnText( ...@@ -345,7 +343,7 @@ void XRMResExport::WorkOnText(
if ( !pResData ) if ( !pResData )
{ {
pResData = new ResData( GetGID() ); pResData.reset( new ResData( GetGID() ) );
} }
pResData->sText[sLang] = rText; pResData->sText[sLang] = rText;
} }
...@@ -363,8 +361,7 @@ void XRMResExport::EndOfText( ...@@ -363,8 +361,7 @@ void XRMResExport::EndOfText(
"Xrmex", pOutputStream, sPath, sResourceType, "Xrmex", pOutputStream, sPath, sResourceType,
pResData->sGId, OString(), OString(), sAct ); pResData->sGId, OString(), OString(), sAct );
} }
delete pResData; pResData.reset();
pResData = NULL;
} }
...@@ -376,8 +373,7 @@ XRMResMerge::XRMResMerge( ...@@ -376,8 +373,7 @@ XRMResMerge::XRMResMerge(
const OString &rFilename ) const OString &rFilename )
: XRMResParser(), : XRMResParser(),
pMergeDataFile( NULL ), pMergeDataFile( NULL ),
sFilename( rFilename ) , sFilename( rFilename )
pResData( NULL )
{ {
if (!rMergeSource.isEmpty() && sLanguage.equalsIgnoreAsciiCase("ALL")) if (!rMergeSource.isEmpty() && sLanguage.equalsIgnoreAsciiCase("ALL"))
{ {
...@@ -400,7 +396,6 @@ XRMResMerge::~XRMResMerge() ...@@ -400,7 +396,6 @@ XRMResMerge::~XRMResMerge()
{ {
pOutputStream.close(); pOutputStream.close();
delete pMergeDataFile; delete pMergeDataFile;
delete pResData;
} }
void XRMResMerge::WorkOnDesc( void XRMResMerge::WorkOnDesc(
...@@ -409,7 +404,7 @@ void XRMResMerge::WorkOnDesc( ...@@ -409,7 +404,7 @@ void XRMResMerge::WorkOnDesc(
{ {
WorkOnText( rOpenTag, rText); WorkOnText( rOpenTag, rText);
if ( pMergeDataFile && pResData ) { if ( pMergeDataFile && pResData ) {
MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData ); MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData.get() );
if ( pEntrys ) { if ( pEntrys ) {
OString sCur; OString sCur;
OString sDescFilename = GetAttribute ( rOpenTag, "xlink:href" ); OString sDescFilename = GetAttribute ( rOpenTag, "xlink:href" );
...@@ -470,8 +465,7 @@ void XRMResMerge::WorkOnDesc( ...@@ -470,8 +465,7 @@ void XRMResMerge::WorkOnDesc(
} }
} }
} }
delete pResData; pResData.reset();
pResData = NULL;
} }
void XRMResMerge::WorkOnText( void XRMResMerge::WorkOnText(
...@@ -480,7 +474,7 @@ void XRMResMerge::WorkOnText( ...@@ -480,7 +474,7 @@ void XRMResMerge::WorkOnText(
{ {
if ( pMergeDataFile ) { if ( pMergeDataFile ) {
if ( !pResData ) { if ( !pResData ) {
pResData = new ResData( GetGID(), sFilename ); pResData.reset( new ResData( GetGID(), sFilename ) );
pResData->sResTyp = sResourceType; pResData->sResTyp = sResourceType;
} }
} }
...@@ -499,7 +493,7 @@ void XRMResMerge::EndOfText( ...@@ -499,7 +493,7 @@ void XRMResMerge::EndOfText(
Output( rCloseTag ); Output( rCloseTag );
if ( pMergeDataFile && pResData ) { if ( pMergeDataFile && pResData ) {
MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData ); MergeEntrys *pEntrys = pMergeDataFile->GetMergeEntrys( pResData.get() );
if ( pEntrys ) { if ( pEntrys ) {
OString sCur; OString sCur;
for( size_t n = 0; n < aLanguages.size(); n++ ){ for( size_t n = 0; n < aLanguages.size(); n++ ){
...@@ -532,8 +526,7 @@ void XRMResMerge::EndOfText( ...@@ -532,8 +526,7 @@ void XRMResMerge::EndOfText(
} }
} }
} }
delete pResData; pResData.reset();
pResData = NULL;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -256,16 +256,14 @@ class ConstantPool : public BlopObject ...@@ -256,16 +256,14 @@ class ConstantPool : public BlopObject
{ {
public: public:
sal_uInt16 m_numOfEntries; sal_uInt16 m_numOfEntries;
sal_Int32* m_pIndex; // index values may be < 0 for cached string constants 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) ConstantPool(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries)
: BlopObject(buffer, len, false) : BlopObject(buffer, len, false)
, m_numOfEntries(numEntries) , m_numOfEntries(numEntries)
, m_pIndex(NULL)
, m_pStringCache(NULL)
{ {
} }
...@@ -292,30 +290,19 @@ public: ...@@ -292,30 +290,19 @@ public:
ConstantPool::~ConstantPool() ConstantPool::~ConstantPool()
{ {
delete[] m_pIndex;
delete m_pStringCache;
} }
sal_uInt32 ConstantPool::parseIndex() sal_uInt32 ConstantPool::parseIndex()
{ {
if (m_pIndex) m_pIndex.reset();
{ m_pStringCache.reset();
delete[] m_pIndex;
m_pIndex = NULL;
}
if (m_pStringCache)
{
delete m_pStringCache;
m_pStringCache = NULL;
}
sal_uInt32 offset = 0; sal_uInt32 offset = 0;
sal_uInt16 numOfStrings = 0; sal_uInt16 numOfStrings = 0;
if (m_numOfEntries) 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++) for (int i = 0; i < m_numOfEntries; i++)
{ {
...@@ -334,7 +321,7 @@ sal_uInt32 ConstantPool::parseIndex() ...@@ -334,7 +321,7 @@ sal_uInt32 ConstantPool::parseIndex()
if (numOfStrings) if (numOfStrings)
{ {
m_pStringCache = new StringCache(numOfStrings); m_pStringCache.reset( new StringCache(numOfStrings) );
} }
m_bufferLen = offset; m_bufferLen = offset;
...@@ -883,13 +870,12 @@ public: ...@@ -883,13 +870,12 @@ public:
sal_uInt16 m_numOfMethodEntries; sal_uInt16 m_numOfMethodEntries;
sal_uInt16 m_numOfParamEntries; sal_uInt16 m_numOfParamEntries;
size_t m_PARAM_ENTRY_SIZE; size_t m_PARAM_ENTRY_SIZE;
sal_uInt32* m_pIndex; std::unique_ptr<sal_uInt32[]> m_pIndex;
ConstantPool* m_pCP; ConstantPool* m_pCP;
MethodList(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries, ConstantPool* pCP) MethodList(const sal_uInt8* buffer, sal_uInt32 len, sal_uInt16 numEntries, ConstantPool* pCP)
: BlopObject(buffer, len, false) : BlopObject(buffer, len, false)
, m_numOfEntries(numEntries) , m_numOfEntries(numEntries)
, m_pIndex(NULL)
, m_pCP(pCP) , m_pCP(pCP)
{ {
if ( m_numOfEntries > 0 ) if ( m_numOfEntries > 0 )
...@@ -926,7 +912,6 @@ private: ...@@ -926,7 +912,6 @@ private:
MethodList::~MethodList() MethodList::~MethodList()
{ {
if (m_pIndex) delete[] m_pIndex;
} }
sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index ) sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index )
...@@ -936,18 +921,14 @@ sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index ) ...@@ -936,18 +921,14 @@ sal_uInt16 MethodList::calcMethodParamIndex( const sal_uInt16 index )
sal_uInt32 MethodList::parseIndex() sal_uInt32 MethodList::parseIndex()
{ {
if (m_pIndex) m_pIndex.reset();
{
delete[] m_pIndex;
m_pIndex = NULL;
}
sal_uInt32 offset = 0; sal_uInt32 offset = 0;
if (m_numOfEntries) if (m_numOfEntries)
{ {
offset = 2 * sizeof(sal_uInt16); 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++) for (int i = 0; i < m_numOfEntries; i++)
{ {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <new> #include <new>
#include <memory>
#include <sal/types.h> #include <sal/types.h>
#include <sal/macros.h> #include <sal/macros.h>
#include <osl/endian.h> #include <osl/endian.h>
...@@ -514,9 +515,9 @@ public: ...@@ -514,9 +515,9 @@ public:
OString m_returnTypeName; OString m_returnTypeName;
RTMethodMode m_mode; RTMethodMode m_mode;
sal_uInt16 m_paramCount; sal_uInt16 m_paramCount;
ParamEntry* m_params; std::unique_ptr<ParamEntry[]> m_params;
sal_uInt16 m_excCount; sal_uInt16 m_excCount;
OString* m_excNames; std::unique_ptr<OString[]> m_excNames;
OString m_doku; OString m_doku;
MethodEntry(); MethodEntry();
...@@ -540,16 +541,12 @@ protected: ...@@ -540,16 +541,12 @@ protected:
MethodEntry::MethodEntry() MethodEntry::MethodEntry()
: m_mode(RTMethodMode::INVALID) : m_mode(RTMethodMode::INVALID)
, m_paramCount(0) , m_paramCount(0)
, m_params(NULL)
, m_excCount(0) , m_excCount(0)
, m_excNames(NULL)
{ {
} }
MethodEntry::~MethodEntry() MethodEntry::~MethodEntry()
{ {
delete[] m_params;
delete[] m_excNames;
} }
void MethodEntry::setData(const OString& name, void MethodEntry::setData(const OString& name,
...@@ -596,11 +593,11 @@ void MethodEntry::reallocParams(sal_uInt16 size) ...@@ -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); 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_paramCount = size;
m_params = newParams; m_params.reset( newParams );
} }
void MethodEntry::reallocExcs(sal_uInt16 size) void MethodEntry::reallocExcs(sal_uInt16 size)
...@@ -620,10 +617,8 @@ void MethodEntry::reallocExcs(sal_uInt16 size) ...@@ -620,10 +617,8 @@ void MethodEntry::reallocExcs(sal_uInt16 size)
newExcNames[i] = m_excNames[i]; newExcNames[i] = m_excNames[i];
} }
delete[] m_excNames;
m_excCount = size; m_excCount = size;
m_excNames = newExcNames; m_excNames.reset( newExcNames );
} }
...@@ -654,7 +649,7 @@ public: ...@@ -654,7 +649,7 @@ public:
sal_uInt16 m_referenceCount; sal_uInt16 m_referenceCount;
ReferenceEntry* m_references; ReferenceEntry* m_references;
sal_uInt8* m_blop; std::unique_ptr<sal_uInt8[]> m_blop;
sal_uInt32 m_blopSize; sal_uInt32 m_blopSize;
TypeWriter(typereg_Version version, TypeWriter(typereg_Version version,
...@@ -701,7 +696,6 @@ TypeWriter::TypeWriter(typereg_Version version, ...@@ -701,7 +696,6 @@ TypeWriter::TypeWriter(typereg_Version version,
, m_methods(NULL) , m_methods(NULL)
, m_referenceCount(referenceCount) , m_referenceCount(referenceCount)
, m_references(NULL) , m_references(NULL)
, m_blop(NULL)
, m_blopSize(0) , m_blopSize(0)
{ {
if (m_nSuperTypes > 0) if (m_nSuperTypes > 0)
...@@ -727,9 +721,6 @@ TypeWriter::~TypeWriter() ...@@ -727,9 +721,6 @@ TypeWriter::~TypeWriter()
if (m_superTypeNames) if (m_superTypeNames)
delete[] m_superTypeNames; delete[] m_superTypeNames;
if (m_blop)
delete[] m_blop;
if (m_fieldCount) if (m_fieldCount)
delete[] m_fields; delete[] m_fields;
...@@ -1151,8 +1142,7 @@ void TypeWriter::createBlop() ...@@ -1151,8 +1142,7 @@ void TypeWriter::createBlop()
delete[] pBlopMethods; delete[] pBlopMethods;
delete[] pBlopReferences; delete[] pBlopReferences;
delete[] m_blop; m_blop.reset( blop );
m_blop = blop;
m_blopSize = blopSize; m_blopSize = blopSize;
} }
...@@ -1259,7 +1249,7 @@ void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * ...@@ -1259,7 +1249,7 @@ void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 *
SAL_THROW_EXTERN_C() SAL_THROW_EXTERN_C()
{ {
TypeWriter * writer = static_cast< TypeWriter * >(handle); TypeWriter * writer = static_cast< TypeWriter * >(handle);
if (writer->m_blop == 0) { if (!writer->m_blop) {
try { try {
writer->createBlop(); writer->createBlop();
} catch (std::bad_alloc &) { } catch (std::bad_alloc &) {
...@@ -1267,7 +1257,7 @@ void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * ...@@ -1267,7 +1257,7 @@ void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 *
} }
} }
*size = writer->m_blopSize; *size = writer->m_blopSize;
return writer->m_blop; return writer->m_blop.get();
} }
static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry) static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment