News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Compiler plugin heap leakage

Started by Grad, March 18, 2013, 02:54:41 PM

Previous topic - Next topic

Grad

Hi,

If we consider the code here below which is making a new instance and returns that.

FileTreeData* CompilerGCC::DoSwitchProjectTemporarily()
{
    ProjectManager* manager = Manager::Get()->GetProjectManager();
    wxTreeCtrl* tree = manager->GetTree();
    wxTreeItemId sel = manager->GetTreeSelection();
    FileTreeData* ftd = sel.IsOk() ? (FileTreeData*)tree->GetItemData(sel) : 0;
    if (!ftd)
        return 0L;
    // copy ftd to a new instance, because after the SetProject() call
    // that follows, ftd will no longer be valid...
    FileTreeData* newFtd = new FileTreeData(*ftd);
    Manager::Get()->GetProjectManager()->SetProject(ftd->GetProject(), false);
    AskForActiveProject();

    return newFtd;
}


but if we call it like that:

void CompilerGCC::OnCompile(wxCommandEvent& event)
{
    int bak = m_RealTargetIndex;
    if (event.GetId() == idMenuCompileFromProjectManager)
    {
        // we 're called from a menu in ProjectManager
        // let's check the selected project...
        DoSwitchProjectTemporarily();
    }
    ProjectBuildTarget* target = 0;
    Build(target);
    m_RealTargetIndex = bak;
}


That new instance is not used and not deleted.

I have changed that to


void CompilerGCC::DoSwitchProjectTemporarily(FileTreeData *ftd /*= NULL*/)
{
    wxTreeCtrl* tree = Manager::Get()->GetProjectManager()->GetTree();
    wxTreeItemId sel = tree->GetSelection();
    FileTreeData* cftd = sel.IsOk() ? (FileTreeData*)tree->GetItemData(sel) : 0;
    if (!cftd)
        return;

    // copy ftd to a new instance, because after the SetProject() call
    // that follows, ftd will no longer be valid...
    if(ftd)
        *ftd = *cftd;

    Manager::Get()->GetProjectManager()->SetProject(cftd->GetProject(), false);
    AskForActiveProject();
}


And call it like:

        FileTreeData ftd;
        DoSwitchProjectTemporarily(&ftd);


If I need the fileTreeData.

Regards.

MortenMacFly

...can you provide a proper patch that works and still enables to compile the whole source code database?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]