- fixed memory leaks in file system management

This commit is contained in:
Christoph Oelckers 2023-09-11 23:19:22 +02:00
parent bdd02d9b2c
commit 7f61266621
3 changed files with 5 additions and 3 deletions

View file

@ -194,7 +194,7 @@ static void PrintLastError (FileSystemMessageFunc Printf);
FileSystem::FileSystem() FileSystem::FileSystem()
{ {
stringpool = new StringPool; stringpool = new StringPool(true);
stringpool->shared = true; // will be used by all owned resource files. stringpool->shared = true; // will be used by all owned resource files.
} }
@ -219,6 +219,8 @@ void FileSystem::DeleteAll ()
delete Files[i]; delete Files[i];
} }
Files.clear(); Files.clear();
delete stringpool;
stringpool = nullptr;
} }
//========================================================================== //==========================================================================

View file

@ -8,7 +8,7 @@ class StringPool
friend class FileSystem; friend class FileSystem;
friend class FResourceFile; friend class FResourceFile;
private: private:
StringPool(size_t blocksize = 10*1024) : TopBlock(nullptr), FreeBlocks(nullptr), BlockSize(blocksize) {} StringPool(bool _shared, size_t blocksize = 10*1024) : TopBlock(nullptr), FreeBlocks(nullptr), BlockSize(blocksize), shared(_shared) {}
public: public:
~StringPool(); ~StringPool();
const char* Strdup(const char*); const char* Strdup(const char*);

View file

@ -332,7 +332,7 @@ FResourceFile *FResourceFile::OpenDirectory(const char *filename, LumpFilterInfo
FResourceFile::FResourceFile(const char *filename, StringPool* sp) FResourceFile::FResourceFile(const char *filename, StringPool* sp)
{ {
stringpool = sp ? sp : new StringPool; stringpool = sp ? sp : new StringPool(false);
FileName = stringpool->Strdup(filename); FileName = stringpool->Strdup(filename);
} }