Author Topic: [BUG] new[] / delete mismatch  (Read 5661 times)

itayperl

  • Guest
[BUG] new[] / delete mismatch
« on: November 18, 2006, 01:08:58 pm »
Hello,

I posted a patch in BerliOS a few days ago and it hasn't been committed or replied to yet, so I am posting it here too in case no one is looking there:

(http://developer.berlios.de/patch/?func=detailpatch&patch_id=1638&group_id=5358)

Code: diff
Index: src/sdk/manager.cpp
===================================================================
--- src/sdk/manager.cpp (revision 3222)
+++ src/sdk/manager.cpp (working copy)
@@ -326,12 +326,12 @@
             wxMemoryFSHandler::AddFile(file, buf, len);
         }
         wxXmlResource::Get()->Load(memoryFile);
-        delete buf;
+        delete[] buf;
         return true;
     }
     catch (...)
     {
-        delete buf;
+        delete[] buf;
         return false;
     }
 }

Regards,

Itay

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: [BUG] new[] / delete mismatch
« Reply #1 on: November 18, 2006, 01:53:28 pm »
True... wonder how that worked for over 3 months :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9701
Re: [BUG] new[] / delete mismatch
« Reply #2 on: November 18, 2006, 01:58:07 pm »
I posted a patch in BerliOS a few days ago [...]
We are not that fast - there are patches much older than that. What came in mind when I saw this particular one: It's missing a few words of explanation. I had to look for myself where the new[] stuff was applied and whether this is correct at all. Please add an explanation next time which will help to easily understand what your patch actually fixes. For example:
"Memory leak detected. You are creating a char buffer array with buf = new char[len]; in bool Manager::LoadResource(const wxString& file) but do not release the memory by delete[] buf;, instead you are only using delete buf;. This patch fixes the issue."
Please understand that this is much easier than reading the raw patches.
With regards, Morten.

Edit: To avoid any misunderstanding: This is a *good* patch, anyway.
« Last Edit: November 18, 2006, 02:05:50 pm by MortenMacFly »
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