From 6a964dcf0fe3b9258d07391ada0f0d245b1f7cec Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Thu, 17 Apr 2014 10:56:03 +0900 Subject: Avoid possible memory leaks in case of exceptions Change-Id: Ibadadacbe09a93e7d7a7210868c52a8fa582d427 --- helpcompiler/source/HelpLinker.cxx | 12 ++++++------ helpcompiler/source/HelpLinker_main.cxx | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'helpcompiler/source') diff --git a/helpcompiler/source/HelpLinker.cxx b/helpcompiler/source/HelpLinker.cxx index 3e1cfd4d29d5..f98c9a2f0545 100644 --- a/helpcompiler/source/HelpLinker.cxx +++ b/helpcompiler/source/HelpLinker.cxx @@ -36,6 +36,8 @@ #include #include +#include +#include IndexerPreProcessor::IndexerPreProcessor ( const std::string& aModuleName, const fs::path& fsIndexBaseDir, @@ -946,9 +948,8 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp xmlSetStructuredErrorFunc( NULL, (xmlStructuredErrorFunc)StructuredXMLErrorFunction ); try { - HelpLinker* pHelpLinker = new HelpLinker(); + boost::scoped_ptr pHelpLinker(new HelpLinker()); pHelpLinker->main( args, &aStdStrExtensionPath, &aStdStrDestination, &aOfficeHelpPath ); - delete pHelpLinker; } catch( const HelpProcessingException& e ) { @@ -980,14 +981,14 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp aFileStatus.isValid( osl_FileStatus_Mask_FileSize ) ) { sal_uInt64 ret, len = aFileStatus.getFileSize(); - char* s = new char[ int(len) ]; // the buffer to hold the installed files + boost::scoped_array s(new char[ int(len) ]); // the buffer to hold the installed files osl::File aFile( aTreeFileURL ); aFile.open( osl_File_OpenFlag_Read ); - aFile.read( s, len, ret ); + aFile.read( s.get(), len, ret ); aFile.close(); XML_Parser parser = XML_ParserCreate( 0 ); - XML_Status parsed = XML_Parse( parser, s, int( len ), true ); + XML_Status parsed = XML_Parse( parser, s.get(), int( len ), true ); if (XML_STATUS_ERROR == parsed) { @@ -1000,7 +1001,6 @@ HELPLINKER_DLLPUBLIC bool compileExtensionHelp } XML_ParserFree( parser ); - delete[] s; } return bSuccess; diff --git a/helpcompiler/source/HelpLinker_main.cxx b/helpcompiler/source/HelpLinker_main.cxx index 83906830b21c..dd22eb99ae8a 100644 --- a/helpcompiler/source/HelpLinker_main.cxx +++ b/helpcompiler/source/HelpLinker_main.cxx @@ -21,6 +21,7 @@ #include #include #include +#include SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { std::vector args; @@ -28,9 +29,8 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { args.push_back(std::string(argv[i])); try { - HelpLinker* pHelpLinker = new HelpLinker(); + boost::scoped_ptr pHelpLinker(new HelpLinker()); pHelpLinker->main( args ); - delete pHelpLinker; } catch( const HelpProcessingException& e ) { -- cgit