ValentijnNK / miranda

Automatically exported from code.google.com/p/miranda
0 stars 0 forks source link

Memory leak due ill-designed code #1694

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Found bad designed code in Miranda IM core:

Look at memory allocation here <b>dblists.cpp</b>:
<code>void List_ObjCopy( SortedList* s, SortedList* d, size_t itemSize )
{
    int i;
    d->increment = s->increment;
    d->sortFunc  = s->sortFunc;
    for ( i = 0; i < s->realCount; i++ ) {
        void* item = new char[ itemSize ];
        memcpy( item, s->items[i], itemSize );
        List_Insert( d, item, i );
    }
}</code>

and memory deallocation here <b>m_system_cpp.h</b>:

<code>
template<class T> struct OBJLIST : public LIST<T>
{
...
__inline void destroy( void )
{   
    for ( int i=0; i < this->count; i++ )
        delete this->items[i];
    #if defined( _STATIC )
        List_Destroy(( SortedList* )this );
    #else
        li.List_Destroy(( SortedList* )this );
    #endif
}</code>

So correct deallocation must be "delete [] this->items[i];" but... it's not 
easy to fix since Miranda IM itself uses this as call of object destructor 
but... I also found several plugins which uses it for scalar types and without 
proper "delete []" produces memory leaks for example in "operator =" calls.

Original issue reported on code.google.com by ryo.rab...@gmail.com on 15 Feb 2013 at 1:37