Browse Source

Fix memory leak in Collada ZAE and 3MF ZipFile reading

Must close the file!
RichardTea 6 years ago
parent
commit
5c6ea5d7ba
2 changed files with 4 additions and 4 deletions
  1. 3 3
      code/3MF/D3MFOpcPackage.cpp
  2. 1 1
      code/Collada/ColladaParser.cpp

+ 3 - 3
code/3MF/D3MFOpcPackage.cpp

@@ -149,14 +149,14 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile)
 
             ASSIMP_LOG_DEBUG(rootFile);
 
+            mZipArchive->Close(fileStream);
+
             mRootStream = mZipArchive->Open(rootFile.c_str());
             ai_assert( mRootStream != nullptr );
             if ( nullptr == mRootStream ) {
                 throw DeadlyExportError( "Cannot open root-file in archive : " + rootFile );
             }
 
-            mZipArchive->Close( fileStream );
-
         } else if( file == D3MF::XmlTag::CONTENT_TYPES_ARCHIVE) {
             ASSIMP_LOG_WARN_F("Ignored file of unsupported type CONTENT_TYPES_ARCHIVES",file);
         } else {
@@ -167,7 +167,7 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile)
 }
 
 D3MFOpcPackage::~D3MFOpcPackage() {
-    // empty
+    mZipArchive->Close(mRootStream);
 }
 
 IOStream* D3MFOpcPackage::RootStream() const {

+ 1 - 1
code/Collada/ColladaParser.cpp

@@ -165,7 +165,7 @@ std::string ColladaParser::ReadZaeManifest(ZipArchiveIOSystem &zip_archive) {
     }
 
     std::unique_ptr<CIrrXML_IOStreamReader> mIOWrapper(new CIrrXML_IOStreamReader(manifestfile.get()));
-    irr::io::IrrXMLReader* manifest_reader = irr::io::createIrrXMLReader(mIOWrapper.get());
+    std::unique_ptr<irr::io::IrrXMLReader> manifest_reader(irr::io::createIrrXMLReader(mIOWrapper.get()));
 
     while (manifest_reader->read())
     {