diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-10-14 15:04:26 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-10-14 15:07:14 +0200 |
commit | 782caa59cc0f72ef377b1d2c99b552b1be201f44 (patch) | |
tree | 3fcac482f653cbbb2db2c055eeda158a59530113 /svx | |
parent | 616445cde0b594de1e6308944d3743cc64cd2a82 (diff) |
svx: fix another temp file leak, from SdrMediaObj's glTF models
These need a whole directory, apparently a model may have multiple
files.
Change-Id: I092c1764ddb1ed30947034f299fbb6882658d21b
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdomedia.cxx | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx index da5860b9c91f..4655ec94c007 100644 --- a/svx/source/svdraw/svdomedia.cxx +++ b/svx/source/svdraw/svdomedia.cxx @@ -41,6 +41,7 @@ // For handling of glTF models #include <unotools/tempfile.hxx> +#include <unotools/localfilehelper.hxx> #include <tools/urlobj.hxx> using namespace ::com::sun::star; @@ -54,10 +55,17 @@ using namespace ::com::sun::star; struct MediaTempFile { OUString const m_TempFileURL; - MediaTempFile(OUString const& rURL) : m_TempFileURL(rURL) {} + OUString const m_TempDirURL; // yet another hack, for the glTF models + MediaTempFile(OUString const& rURL, OUString const& rDirURL) + : m_TempFileURL(rURL), m_TempDirURL(rDirURL) + {} ~MediaTempFile() { ::osl::File::remove(m_TempFileURL); + if (!m_TempDirURL.isEmpty()) + { + ::utl::removeTree(m_TempDirURL); + } } }; @@ -270,10 +278,11 @@ uno::Reference<io::XInputStream> SdrMediaObj::GetInputStream() static bool lcl_HandleJsonPackageURL( const OUString& rURL, SdrModel* const pModel, - OUString& o_rTempFileURL) + OUString& o_rTempFileURL, + OUString& o_rTempDirURL) { // Create a temporary folder which will contain all files of glTF model - const OUString sTempFolder = ::utl::TempFile( NULL, true ).GetURL(); + o_rTempDirURL = ::utl::TempFile(NULL, true).GetURL(); const sal_uInt16 nPackageLength = OString("vnd.sun.star.Package:").getLength(); const OUString sUrlPath = rURL.copy(nPackageLength,rURL.lastIndexOf("/")-nPackageLength); @@ -298,7 +307,7 @@ static bool lcl_HandleJsonPackageURL( { // Generate temp file path const OUString& rFilename = aFilenames[nFileIndex]; - INetURLObject aUrlObj(sTempFolder); + INetURLObject aUrlObj(o_rTempDirURL); aUrlObj.insertName(rFilename); const OUString sFilepath = aUrlObj.GetMainURL( INetURLObject::NO_DECODE ); @@ -367,7 +376,7 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL); if (bSuccess) { - m_pImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL)); + m_pImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL, "")); m_pImpl->m_MediaProperties.setURL( m_pImpl->m_LastFailedPkgURL, tempFileURL, ""); } @@ -429,16 +438,18 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper rNewProperties.getTempURL())) { OUString tempFileURL; + OUString tempDirURL; bool bSuccess; #if HAVE_FEATURE_GLTF if( url.endsWith(".json") ) - bSuccess = lcl_HandleJsonPackageURL(url, GetModel(), tempFileURL); + bSuccess = lcl_HandleJsonPackageURL(url, GetModel(), tempFileURL, tempDirURL); else #endif - bSuccess = lcl_HandlePackageURL( url, GetModel(), tempFileURL); + bSuccess = lcl_HandlePackageURL(url, GetModel(), tempFileURL); if (bSuccess) { - m_pImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL)); + m_pImpl->m_pTempFile.reset( + new MediaTempFile(tempFileURL, tempDirURL)); m_pImpl->m_MediaProperties.setURL(url, tempFileURL, ""); } else // this case is for Clone via operator= |