Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

HUGE MEMORY LEAK pinpointed!

(1/21) > >>

rickg22:
Hey guys, I think I know why some of the plugins (like the TODO list and perhaps even Code Completion) waste too much memory!

Look!


--- Code: ---bool cbRead(wxFile& file, wxString& st, wxFontEncoding encoding)
{
    st.Empty();
    if (!file.IsOpened())
        return false;
    int len = file.Length();
    if(!len)
    {
        file.Close();
        return true;
    }

    char* buff = new char[len+1];
    if (!buff)
    {
        file.Close();
        return false;
    }
    file.Read((void*)buff, len);
    file.Close();
    buff[len]='\0';

DetectEncodingAndConvert(buff, st, encoding);
// NOW WHERE'S DELETE BUFF?????????

    return true;
}

--- End code ---

Notice that DetectEncodingAndConvert takes for parameter a const char*, so it means it doesn't do anything to buff. However, buff isn't released at the end. Hence, the leak.

I'll add a delete operator and see if nothing breaks.

rickg22:
Update: It works!!!  :o

Memory consumption with the TODO plugin remains *steady* at 42MB!

I wonder how will code completion be affected with this... hmmm :)
Holy Cow...  :shock: 42MB was *WITH* code completion!!!! (No global includes tho, with them it's around 100mb). Without it's *JUST* 27.6MB! Woo hoo!!!!!!!

I'll commit ASAP.

(Hmm.......... code completion does leak. Everytime i parse, memory consumption is increased. But that'll be another adventure! :D )

David Perfors:
wow, that is a nice catch :) great work rick :D

MortenMacFly:
Wow... how ugly... must patch my C::B to have some testing... Well done, Rick! :P

jpaterso:
Nicely picked up.
Recompiling my C::B now!

Navigation

[0] Message Index

[#] Next page

Go to full version