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::operator= ( const Queue& original_copy )
{
if ( ( &original_copy ) == this ) return false;
Clear(_FILE_ANDLINE);
// 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::Push( const queue_type& input, const char *file, unsigned int line )
{
if ( allocation_size == 0 )
{
array = RakNet::OP_NEW_ARRAY(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.
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::operator= ( const Queue& original_copy )
{
if ( ( &original_copy ) == this ) return false;
Clear(_FILE_ANDLINE);
// 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::Push( const queue_type& input, const char *file, unsigned int line )
{
if ( allocation_size == 0 )
{
array = RakNet::OP_NEW_ARRAY(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.