Re: Error on deleting pointer
Re: Error on deleting pointer
- Subject: Re: Error on deleting pointer
- From: Jos Timanta Tarigan <email@hidden>
- Date: Mon, 12 Sep 2011 07:49:38 -0700 (PDT)
Hi,
I seems not to understand what went wrong with my code. I use guard malloc and it catches this error when I delete the pointer in the destructor of an object.
~ObjectX() {
delete [] bgArr; // malloc error occured here
};
When I run it without guard malloc, the code runs, but the console prints the error.
But when I try to simulate/reproduce it in a much smaller code, I cant reproduce the error. Its a little bit confusing.
I googled it and it seems like most result return an OSX/iOS/XCode related. Is there a chance that its a bug on XCode/Compiler? I'm using XCode 4.0 Snow Leopard with LLVM GCC 4.2.
regards
=================================
svnstrk
From: Jens Alfke <email@hidden>
To: Jos Timanta Tarigan <email@hidden>
Cc: "email@hidden" <email@hidden>
Sent: Sunday, September 11, 2011 3:23 AM
Subject: Re: Error on deleting pointer
On Sep 10, 2011, at 7:37 AM, Jos Timanta Tarigan wrote:
> GuardMalloc[FighterTD-23087]: guard malloc zone failure: freeing a pointer we didn't allocate that was not claimed by any registered zone
> GuardMalloc[FighterTD-23087]: Explicitly trapping into debugger!!!
>
> the error occurs when I try to delete a pointer (which is treated as an array).
It’s not a valid
pointer, then. The message is simply telling you that the address passed to free() doesn’t correspond to any existing malloc()ed block. The pointer might be to an already-freed block, or the pointer value might be garbage. This is a typical kind of bug when writing C/C++ level code, nothing OS X specific at all.
Since you say you’re deleting an array, make sure you understand the difference between “delete x” and “delete [] x”, and check that you’re using the correct one.
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden