Xcode 4.5.1, ARC enabled.

I've this C++ member function, for a testing environment (gtest):


NSDictionary* fetchUser(NSNumber* ID, NSError** error)
{
    id user = nil;
    //@autoreleasepool   // crashes when @autoreleasepool is enabled
    {
        id data = ...; // response body of a HTTP Response (NSData) or NSError 
object, never nil.
        if ([data isKindOfClass:[NSData class]]) {
            user = [NSJSONSerialization JSONObjectWithData:data
                                                      options:0
                                                        error:error];
        }
        else if (error) {
            *error = data;
        }
    } // autoreleasepool
    return user;
}



The problem here is, if the autorelease pool is **enabled**, I get a crash in 
the caller's code:
            NSError* err = nil;
            NSDictionary* deletedUser = this->fetchUser(userID, &err);
            EXPECT_TRUE(deletedUser == nil);    <== the crash occurs **before** 
this statement, but **after** the return statement of the function fetch user.

The debugger does not show a stack frame to confirm this, though.

        libobjc.A.dylib`objc_msgSend:
        0x7fff86b2fe80:  testq  %rdi, %rdi
        0x7fff86b2fe83:  je     0x7fff86b2feb0            ; objc_msgSend + 48
        0x7fff86b2fe85:  testb  $1, %dil
        0x7fff86b2fe89:  jne    0x7fff86b2fec7            ; objc_msgSend + 71
        0x7fff86b2fe8c:  movq   (%rdi), %r11              
        0x7fff86b2fe8f:  pushq  %rax
==>     0x7fff86b2fe90:  movq   16(%r11), %r10          // Thread 1: 
EXC_BAD_ACCESS (code=13, address=0x0)
        0x7fff86b2fe94:  movl   %esi, %eax
        0x7fff86b2fe96:  andl   (%r10), %eax
        0x7fff86b2fe99:  movq   16(%r10,%rax,8), %r11
        0x7fff86b2fe9e:  incl   %eax
        0x7fff86b2fea0:  testq  %r11, %r11
        0x7fff86b2fea3:  je     0x7fff86b2fedb            ; objc_msgSend + 91
                 ...

There is no stack frame.


This has something to do with the error parameter. If I pass nil for the error 
parameter, the crash does not occur anymore.


Any hints?


Thanks in advance!

Andreas
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to