datapack: free all elements on clear (#1251)
* Fixed memory leak When a pack was cleared or destroyed the String and Raw types could cause memory leaks. This happens when "position" is sitting at the end of the vector and can never get past the "if (pos >= elements.length())" statement. This means there is a memory leak in any plugin that clears/destroys a pack with strings and doesn't set the position to length-1 or less beforehand. * datapack: Fix delete op on CDataPackType::Raw. Co-authored-by: Kyle Sanderson <kyle.leet@gmail.com>
This commit is contained in:
parent
d42c304a55
commit
d044b13ce4
@ -65,12 +65,13 @@ CDataPack::Free(CDataPack *pack)
|
|||||||
|
|
||||||
void CDataPack::Initialize()
|
void CDataPack::Initialize()
|
||||||
{
|
{
|
||||||
|
position = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
} while (this->RemoveItem());
|
} while (this->RemoveItem());
|
||||||
|
|
||||||
elements.clear();
|
elements.clear();
|
||||||
position = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDataPack::ResetSize()
|
void CDataPack::ResetSize()
|
||||||
@ -214,6 +215,7 @@ bool CDataPack::RemoveItem(size_t pos)
|
|||||||
{
|
{
|
||||||
pos = position;
|
pos = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos >= elements.length())
|
if (pos >= elements.length())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -228,7 +230,7 @@ bool CDataPack::RemoveItem(size_t pos)
|
|||||||
{
|
{
|
||||||
case CDataPackType::Raw:
|
case CDataPackType::Raw:
|
||||||
{
|
{
|
||||||
delete elements[pos].pData.vval;
|
delete [] elements[pos].pData.vval;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user