Bug #19248 2014-01-05 14:51

lights_joy

Memory Leak at cbProject::VirtualFolderAdded

hello, I'm using c::b 12.11
there is a bug at the function:
bool cbProject::VirtualFolderAdded(wxTreeCtrl* tree, wxTreeItemId parent_node, const wxString& virtual_folder)
{
    wxString foldername = GetRelativeFolderPath(tree, parent_node);
    foldername << virtual_folder;
    foldername.Replace(_T("/"),  wxString(wxFILE_SEP_PATH), true);
    foldername.Replace(_T("\\"), wxString(wxFILE_SEP_PATH), true);
    if (foldername.Last() != wxFILE_SEP_PATH)
        foldername << wxFILE_SEP_PATH;

    for (size_t i = 0; i < m_VirtualFolders.GetCount(); ++i)
    {
        if (m_VirtualFolders[i].StartsWith(foldername))
        {
            cbMessageBox(_("A virtual folder with the same name already exists."),
                        _("Error"), wxICON_WARNING);
            return false;
        }
    }
    m_VirtualFolders.Add(foldername);

   FileTreeData* ftd = new FileTreeData(this, FileTreeData::ftdkVirtualFolder);    
ftd->SetProjectFile(0);
    ftd->SetFolder(foldername);

    int vfldIdx = Manager::Get()->GetProjectManager()->VirtualFolderIconIndex();

    AddTreeNode(tree, foldername, m_ProjectNode, true, FileTreeData::ftdkVirtualFolder, true, vfldIdx, ftd);
    if (!tree->IsExpanded(parent_node))
        tree->Expand(parent_node);

    SetModified(true);

//    Manager::Get()->GetLogManager()->DebugLog(F(_T("VirtualFolderAdded: %s: %s"), foldername.c_str(), GetStringFromArray(m_VirtualFolders, _T(";")).c_str()));
    return true;
}

the ftd pointer MUST be delete when leaved the function, is that right?

in the function AddTreeNode, it malloc a new FileTreeData and copy the content of this pointer, so there is a memory leak here.


Category
Application::WrongBehaviour
Group
Platform:Windows
Status
Open
Close date
 
Assigned to
 
ollydbg 2014-02-28 06:03

c::b 12.11 is a big old, but can you check the latest trunk code? Thanks.