szone error on alloc

Member
Posts: 306
Joined: 2009.03
Post: #1
I am trying to track down an issue. I have the following line producing an szone exception:
children = [[NSMutableArray arrayWithCapacity:4] retain];

After my breakpoint is hit, if I hit play I see:
On the console I see:

malloc: *** error for object 0x3dc6440: incorrect checksum for freed object - object was probably modified after being freed.

What I don't understand is why is mallocing causing a modify issue. Shouldn't this just be getting new memory? I would have thought this kind of exception would happen if I tried to set a value on an existing object after that object was freeed.

Does anyone have any ideas?
This is one of those random things as I can run my app for a bit and not see anything and its doing the same thing over and over and this randomly pops up.

Thanks!
Quote this message in a reply
⌘-R in Chief
Posts: 1,265
Joined: 2002.05
Post: #2
The problem is not that line, it's something else.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #3
I think I figured it out. Let me know if this makes sense:

file xyz.h
typedef struct _AnimationSequenceData* AnimationSequenceDataRef;

file xyz.m
typedef struct _AnimationSequenceData
{
int currentStep;
CGPoint totalPositionDelta;
GLfloat totalRotationDelta;
GLfloat stepTimedPassed;
}AnimationSequenceData;


Thats a struct defined.
Elsewhere in that file i was doing a malloc using sizeof(AnimationSequenceDataRef)
But the ref maybe is just the pointer and not the size of the object.

I was able to make the problem go away it appears by switching the sizeof to use the full definition(AnimationSequenceData). Does this sound accurate?
Quote this message in a reply
⌘-R in Chief
Posts: 1,265
Joined: 2002.05
Post: #4
Yep.        
Quote this message in a reply
Post Reply