Author Topic: Compiler plugin heap leakage  (Read 5404 times)

Offline Grad

  • Single posting newcomer
  • *
  • Posts: 9
Compiler plugin heap leakage
« on: March 18, 2013, 02:54:41 pm »
Hi,

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

Code
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:

Code
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

Code
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:

Code
        FileTreeData ftd;
        DoSwitchProjectTemporarily(&ftd);

If I need the fileTreeData.

Regards.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Compiler plugin heap leakage
« Reply #1 on: March 18, 2013, 04:21:53 pm »
...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: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ