Compare commits

...

4 Commits

Author SHA1 Message Date
Kim Kulling c25b13e692
Merge branch 'master' into kimkulling/close_memleak-issue-3416 2023-02-03 17:57:11 +01:00
Kim Kulling 8cb0a59f95
Update MemoryIOWrapper.h 2023-02-03 12:57:23 +01:00
Kim Kulling 8030a3264a
Update MemoryIOWrapper.h 2023-02-02 21:04:50 +01:00
Kim Kulling 1eb2c124a0
Fix: Close leak.
- closes https://github.com/assimp/assimp/issues/3416
2023-02-02 20:52:40 +01:00
1 changed files with 15 additions and 12 deletions

View File

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2023, assimp team
All rights reserved.
@ -66,11 +65,7 @@ namespace Assimp {
// ----------------------------------------------------------------------------------
class MemoryIOStream : public IOStream {
public:
MemoryIOStream (const uint8_t* buff, size_t len, bool own = false)
: buffer (buff)
, length(len)
, pos((size_t)0)
, own(own) {
MemoryIOStream (const uint8_t* buff, size_t len, bool own = false) : buffer (buff), length(len), pos((size_t)0), own(own) {
// empty
}
@ -162,7 +157,11 @@ public:
}
/** Destructor. */
~MemoryIOSystem() = default;
~MemoryIOSystem() {
for (auto &it : created_streams) {
delete it;
}
}
// -------------------------------------------------------------------
/** Tests for the existence of a file at the given path. */
@ -176,18 +175,22 @@ public:
// -------------------------------------------------------------------
/** Returns the directory separator. */
char getOsSeparator() const override {
return existing_io ? existing_io->getOsSeparator()
: '/'; // why not? it doesn't care
return existing_io ? existing_io->getOsSeparator() : '/';
}
// -------------------------------------------------------------------
/** Open a new file with a given path. */
/// Open a new file with a given path.
IOStream* Open(const char* pFile, const char* pMode = "rb") override {
if (pFile == nullptr) {
return nullptr;
}
if ( 0 == strncmp( pFile, AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH ) ) {
created_streams.emplace_back(new MemoryIOStream(buffer, length));
return created_streams.back();
}
return existing_io ? existing_io->Open(pFile, pMode) : NULL;
return existing_io ? existing_io->Open(pFile, pMode) : nullptr;
}
// -------------------------------------------------------------------