facebookarchive / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
3.3k stars 1.02k forks source link

Memory Leak Issue !!! #73

Open Kiddinglife opened 8 years ago

Kiddinglife commented 8 years ago

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.

larku commented 8 years ago

Ouch, I'll fix that in the larku fork over the next few weeks.