Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

[BUG] new[] / delete mismatch

(1/1)

itayperl:
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;
     }
 }

--- End code ---

Regards,

Itay

thomas:
True... wonder how that worked for over 3 months :)

MortenMacFly:

--- Quote from: itayperl on November 18, 2006, 01:08:58 pm ---I posted a patch in BerliOS a few days ago [...]

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version