Skip navigation.
 
mlRe: Crash when creating instance of class
FROM : Guy English
DATE : Tue Nov 23 20:27:43 2004

Hi,

I think this:
>        id person = (id)malloc ( sizeof(id) );
>        id alias = person;
>        alias->isa = AIPerson;
>        [alias init];


Is going to crash anyway because you're only allocating enough space
for an object with no ivars. Once you call init AIPerson is going to
stamp all over memory that it doesn't have. I think. :) Haven't looked
at the runtime in ages and I'm not in front of my Mac.

> On Nov 23, 2004, at 9:35 AM, Jason Bell wrote:
> > Exception:  EXC_BAD_ACCESS (0x0001)
> > Codes:      KERN_PROTECTION_FAILURE (0x0002) at 0x00000010


Nutty. :) Can we see the header for the class? The address it's
stamping on makes it look like the malloc is failing, returning NULL
then the init code goes on to write to it anyway and the first var it
tries to write to happens to be at offset 0x00000010. That's my guess
anyway. Now why the malloc is failing I dunno and why the runtime
doesn't check I dunno either. :) But looking that the header could
give us a few hints.

Take care,
Guy

Related mailsAuthorDate
mlCrash when creating instance of class Jason Bell Nov 23, 18:35
mlRe: Crash when creating instance of class Scott Stevenson Nov 23, 19:57
mlRe: [SOLVED] Crash when creating instance of class Jason Bell Nov 23, 20:20
mlRe: Crash when creating instance of class Guy English Nov 23, 20:27