Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
BUG: Memory Leak at cbProject::VirtualFolderAdded
lights_joy:
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.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.
ollydbg:
--- Code: ---AddTreeNode(tree, foldername, m_ProjectNode, true, FileTreeData::ftdkVirtualFolder, true, vfldIdx, ftd);
--- End code ---
My guess is that this pointer is hold in the tree, so when the tree node destroys, ftd will be deleted, this is only my guess.
lights_joy:
I compiled C::B using vs2012, and when I execute the above code, there is a memory leak message when i close C::B.
but if i delete the ftd pointer here, it's all OK.
ollydbg:
--- Quote from: lights_joy on January 06, 2014, 04:02:27 pm ---I compiled C::B using vs2012, and when I execute the above code, there is a memory leak message when i close C::B.
but if i delete the ftd pointer here, it's all OK.
--- End quote ---
Thanks for the test.
--- Quote ---in the function AddTreeNode, it malloc a new FileTreeData and copy the content of this pointer, so there is a memory leak here.
--- End quote ---
Oh, it is definitely a bug here as you said. :)
BTW: Some one may be interested to see a VC project file for C::B source code, how do you did that? Share it? Thanks.
ollydbg:
Some information:
At SVN revision 9194(sure it is after 12.11 release), those code was changed to something like:
--- Quote ---Revision: b48f1749e8766e286b4d8c908aac933cae1b6ac8
Author: fuscated <fuscated@2a5c6006-c6dd-42ca-98ab-0921f2732cef>
Date: 2013-7-9 7:06:38
Message:
* sdk: Move lots of code related to the projects tree from cbProject to ProjectManagerUI
git-svn-id: http://svn.code.sf.net/p/codeblocks/code/trunk@9194 2a5c6006-c6dd-42ca-98ab-0921f2732cef
----
Modified: src/include/cbproject.h
Modified: src/include/projectfile.h
Modified: src/sdk/cbproject.cpp
Modified: src/src/projectmanagerui.cpp
Modified: src/src/projectmanagerui.h
--- End quote ---
--- Code: ---void ProjectManagerUI::OnAddVirtualFolder(cb_unused wxCommandEvent& event)
{
wxString fld = wxGetTextFromUser(_("Please enter the new virtual folder path:"), _("New virtual folder"));
if (fld.IsEmpty())
return;
wxTreeItemId sel = GetTreeSelection();
if (!sel.IsOk())
return;
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
cbProject* prj = ftd->GetProject();
if (!prj)
return;
ProjectVirtualFolderAdded(prj, m_pTree, sel, fld);
// RebuildTree();
}
--- End code ---
So, do you think it still have memory leak about ftd?
Navigation
[0] Message Index
[#] Next page
Go to full version