mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Fix memory leak in ZipSubRStream
Inside attachStream() method we may clone passed stream, but never delete it.
This commit is contained in:
parent
2bacfca540
commit
5e8af7020c
2 changed files with 9 additions and 3 deletions
|
|
@ -700,7 +700,7 @@ Stream * ZipArchive::openFile(const char *filename, ZipEntry* ze, AccessMode mod
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZipArchive::closeFile(Stream *stream)
|
void ZipArchive::closeFile(Stream *stream, bool deleteRootStream /*= false*/)
|
||||||
{
|
{
|
||||||
FilterStream *currentStream, *nextStream;
|
FilterStream *currentStream, *nextStream;
|
||||||
|
|
||||||
|
|
@ -724,6 +724,11 @@ void ZipArchive::closeFile(Stream *stream)
|
||||||
// so we need to update the relevant information in the header.
|
// so we need to update the relevant information in the header.
|
||||||
updateFile(tempStream);
|
updateFile(tempStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [bank / Feb-2025] If the stream was cloned (via openFileForRead method)
|
||||||
|
// we should clean it up and delete, otherwise it will rest in memory forever.
|
||||||
|
if (deleteRootStream && stream != mStream)
|
||||||
|
delete stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -888,7 +893,8 @@ bool ZipArchive::extractFile(const char *pathInZip, const char *filename, bool *
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeFile(source);
|
// Pass deleteRootStream flag to drop cloned FileStream
|
||||||
|
closeFile(source, true);
|
||||||
dest.close();
|
dest.close();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ public:
|
||||||
/// @param stream Stream to close
|
/// @param stream Stream to close
|
||||||
/// @see ZipArchive::openFile(const char *, AccessMode)
|
/// @see ZipArchive::openFile(const char *, AccessMode)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
virtual void closeFile(Stream *stream);
|
virtual void closeFile(Stream *stream, bool deleteRootStream = false);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/// @brief Open a file within the zip file for read
|
/// @brief Open a file within the zip file for read
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue