Memory Leak Issue !!!
Kiddinglife opened this issue · 1 comments
I found memory leak issue everytime I assign a new queue to an old queue by using operator=. After debuging the source codes line by line in raknet, i found there is a bug in the impl of operator= function in line of 303 - 307 in DS_Queue.h file:
template
bool Queue<queue_type>::operator= ( const Queue& original_copy )
{
if ( ( &original_copy ) == this ) return false;
Clear(FILE_AND_LINE);
// Allocate memory for copy
if ( original_copy.Size() == 0 ) ///line 303
{
allocation_size = 0; /
} ///line 307
........
As you see, when original queue has size of 0, raknet just simply updates allocation_size to 0.
template
void Queue<queue_type>::Push( const queue_type& input, const char *file, unsigned int line )
{
if ( allocation_size == 0 )
{
array = RakNet::OP_NEW_ARRAY<queue_type>(16, file, line );
head = 0;
tail = 1;
array[ 0 ] = input;
allocation_size = 16;
return ;
}
......
So, When you then push a new element to this queue, you will get memory leak withput deleting the old array.
Ouch, I'll fix that in the larku fork over the next few weeks.