Fixed: Memory leaks in CBigFile

--HG--
branch : develop
This commit is contained in:
kervala 2016-12-04 16:54:57 +01:00
parent 8cc3963ddd
commit 91d6734e2a
2 changed files with 26 additions and 3 deletions

View file

@ -112,7 +112,8 @@ public:
// A BNP structure // A BNP structure
struct BNP struct BNP
{ {
BNP() : FileNames(NULL), ThreadFileId(0), CacheFileOnOpen(false), AlwaysOpened(false), InternalUse(false), OffsetFromBeginning(0) { } BNP();
~BNP();
// FileName of the BNP. important to open it in getFile() (for other threads or if not always opened). // FileName of the BNP. important to open it in getFile() (for other threads or if not always opened).
std::string BigFileName; std::string BigFileName;
@ -163,6 +164,7 @@ private:
{ {
public: public:
CThreadFileArray(); CThreadFileArray();
~CThreadFileArray();
// Allocate a FileId for a BNP. // Allocate a FileId for a BNP.
uint32 allocate(); uint32 allocate();

View file

@ -47,6 +47,14 @@ CBigFile::CThreadFileArray::CThreadFileArray()
{ {
_CurrentId = 0; _CurrentId = 0;
} }
// ***************************************************************************
CBigFile::CThreadFileArray::~CThreadFileArray()
{
vector<CHandleFile> *ptr = (vector<CHandleFile>*)_TDS.getPointer();
if (ptr) delete ptr;
}
// *************************************************************************** // ***************************************************************************
uint32 CBigFile::CThreadFileArray::allocate() uint32 CBigFile::CThreadFileArray::allocate()
{ {
@ -186,11 +194,24 @@ void CBigFile::remove (const std::string &sBigFileName)
fclose (handle.File); fclose (handle.File);
handle.File= NULL; handle.File= NULL;
} }
delete [] rbnp.FileNames;
_BNPs.erase (it); _BNPs.erase (it);
} }
} }
CBigFile::BNP::BNP() : FileNames(NULL), ThreadFileId(0), CacheFileOnOpen(false), AlwaysOpened(false), InternalUse(false), OffsetFromBeginning(0)
{
}
CBigFile::BNP::~BNP()
{
if (FileNames)
{
delete[] FileNames;
FileNames = NULL;
}
}
//// *************************************************************************** //// ***************************************************************************
bool CBigFile::BNP::readHeader() bool CBigFile::BNP::readHeader()
{ {