Author Topic: BUG: Memory Leak at CompilerGCC::PrepareCompileFilePM  (Read 5495 times)

Offline lights_joy

  • Multiple posting newcomer
  • *
  • Posts: 13
BUG: Memory Leak at CompilerGCC::PrepareCompileFilePM
« on: January 08, 2014, 04:16:39 pm »
in the release code of 12.11

Code
void CompilerGCC::PrepareCompileFilePM(wxFileName& file)
{
    // we 're called from a menu in ProjectManager
    // let's check the selected project...
    [color=red]FileTreeData* ftd = DoSwitchProjectTemporarily();[/color]
    ProjectFile* pf = ftd->GetProjectFile();
    if (!pf)
        return;

    file = pf->file;
    CheckProject();
}


the ftd pointer here is malloc in DoSwitchProjectTemporarily function, but no use here, so it MUST be deleted, or it will result in a memory leak!


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: BUG: Memory Leak at CompilerGCC::PrepareCompileFilePM
« Reply #1 on: January 08, 2014, 07:32:44 pm »
Please check if this problem exists in the SVN sources and report back. Almost no one here is interested in 12.11 any more!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline lights_joy

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: BUG: Memory Leak at CompilerGCC::PrepareCompileFilePM
« Reply #2 on: January 22, 2014, 02:36:27 pm »
this bug still exists at 13.12.
everywhere call the DoSwitchProjectTemporarily function will cause a memory leak!! :'(

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7787
    • My Best Post
Re: BUG: Memory Leak at CompilerGCC::PrepareCompileFilePM
« Reply #3 on: January 22, 2014, 02:56:55 pm »
this bug still exists at 13.12.
everywhere call the DoSwitchProjectTemporarily function will cause a memory leak!! :'(

Please read this other thread you started!

http://forums.codeblocks.org/index.php/topic,18756.msg128544.html#msg128544
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: BUG: Memory Leak at CompilerGCC::PrepareCompileFilePM
« Reply #4 on: January 26, 2014, 03:38:49 pm »
This patch should fix the problem. I'll wait for a few day and if there are no objections I'll commit it.

Code
Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp     (revision 9609)
+++ src/plugins/compilergcc/compilergcc.cpp     (working copy)
@@ -1073,16 +1073,14 @@ FileTreeData* CompilerGCC::DoSwitchProjectTemporarily()
     ProjectManager* manager = Manager::Get()->GetProjectManager();
     wxTreeCtrl* tree = manager->GetUI().GetTree();
     wxTreeItemId sel = manager->GetUI().GetTreeSelection();
-    FileTreeData* ftd = sel.IsOk() ? (FileTreeData*)tree->GetItemData(sel) : 0;
+    FileTreeData* ftd = sel.IsOk() ? (FileTreeData*)tree->GetItemData(sel) : nullptr;
     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);
+        return nullptr;
+    // We're not rebuilding the tree, so the ftd pointer is still valid after the call.
     Manager::Get()->GetProjectManager()->SetProject(ftd->GetProject(), false);
     AskForActiveProject();

-    return newFtd;
+    return ftd;
 }

 void CompilerGCC::AddToCommandQueue(const wxArrayString& commands)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]