From a975d17e715bcf317e40d19ef47cc37660b81f7e Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 15 Jan 2019 07:22:37 +0100 Subject: Use utl::TempFile for exception safety ... to not leak temporary cat files Change-Id: I99e230054f1a3ed6aabce63d427483808e969716 Reviewed-on: https://gerrit.libreoffice.org/66343 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- desktop/source/app/dispatchwatcher.cxx | 41 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'desktop/source/app') diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 21fa4ff6b956..3a8b2d9961a0 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -579,12 +580,15 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector fileForCat; if( aDispatchRequest.aRequestType == REQUEST_CAT ) { - if( ::osl::FileBase::createTempFile(nullptr, nullptr, &fileForCat) != ::osl::FileBase::E_None ) + fileForCat = std::make_unique(); + if (fileForCat->IsValid()) + fileForCat->EnableKillingFile(); + else std::cerr << "Error: Cannot create temporary file..." << std::endl ; - aOutFile = fileForCat; + aOutFile = fileForCat->GetURL(); } if ( bGuess ) @@ -657,33 +661,18 @@ bool DispatchWatcher::executeDispatchRequests( const std::vectorIsValid()) { - osl::File aFile(fileForCat); - osl::File::RC aRC = aFile.open(osl_File_OpenFlag_Read); - if (aRC != osl::File::E_None) - { - std::cerr << "Error: Cannot read from temp file" << std::endl; - } - else + SvStream* aStream = fileForCat->GetStream(StreamMode::STD_READ); + while (aStream->good()) { - sal_Bool eof; - for (;;) + OString aStr; + aStream->ReadLine(aStr, SAL_MAX_INT32); + for (sal_Int32 i = 0; i < aStr.getLength(); ++i) { - aFile.isEndOfFile( &eof ); - if (eof) - break; - rtl::ByteSequence bseq; - aFile.readLine(bseq); - unsigned const char * aStr = reinterpret_cast(bseq.getConstArray()); - for (sal_Int32 i = 0; i < bseq.getLength(); ++i) - { - std::cout << aStr[i]; - } - std::cout << std::endl; + std::cout << aStr[i]; } - aFile.close(); - osl::File::remove(fileForCat); + std::cout << std::endl; } } } -- cgit