Cant find bug, EXC_BAD_ACCESS

0

Last time I posted on Stackowerflow I screwed up because thought I knew more than I did. Renamed methods to make it easier and just made everything very confusing. So I am going to make another try now.

Anyways, my application have been rejected a couple of times by Apple and I can´t find the bug. I have been running the simulator as well as AD-HOC install and can’t seem to find the bug or even replicate it.

I have no warnings and have been using static analyzer and can´t find any problems there either.

I am new to Objective C and think that I am doing something wrong with how I am using class methods but I am not sure.

It´s the last one, the class method ”itemStatus” that crashes.

Im am using ARC by the way.

Any help would be much appreciated.

   Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x432b2b10
    Crashed Thread:  0

    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0 Crashed:
    0   libobjc.A.dylib                 0x3a3c3526 objc_retain + 6
    1   Kebunno                     0x0008928a +[DynamoDBManager itemStatus] + 418
    2   Kebunno                     0x000894de +[DynamoDBManager getItem:] + 170
    3   Kebunno                     0x000908f6 __44-[KebunnoViewController itemPressed]_block_invoke + 362

First class

@interface KebunnoViewController ()

// Interface declarations here

@end


@implementation KebunnoViewController

- (IBAction)itemPressed:(id)sender {
    NSString *itemID = _itemID.text;
    NSString *reference = _reference.text;


    BOOL itemCorrect = NO;
    if([ItemHelpClass validItem:itemID]){
    itemCorrect = YES;
    }

    if(!itemCorrect){
        [[ItemHelpClass showItemNotCorrect:self] show];
        return;
    }


    else if(itemCorrect){
        [self startCancelTimer];
        [self disableButtons];

        dispatch_queue_t backgroundQueue = dispatch_queue_create("background queue", NULL);
        dispatch_async(backgroundQueue, ^{
            NSString *itemStatus;
            itemStatus = [DynamoDBManager getItem:itemID]; //crash

         if([itemStatus isEqualToString:NETWORK_ERROR] || 
          [itemStatus  isEqualToString:AMAZON_ERROR]){
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self enableButtons];
                    [[ItemHelpClass showSomethingWentWrong:self] show];
                });
            }

//Code continues
}

@end

Another file called DynamoDBMangar.m

@implementation DynamoDBManager

+(NSString*)getItem:(NSString *)itemID {
    NetworkStatus netStatus = 
    [[Reachability reachabilityForInternetConnection]currentReachabilityStatus];

    if(netStatus == NotReachable)
    {
        return NETWORK_ERROR;
    }

    NSString *itemStatus = [self itemStatus]; //crash
    if([itemStatus isEqualToString: ITEM_BORROWED]){
        return ITEM_BORROWED;
    }
    else if([itemStatus isEqualToString:NETWORK_ERROR])
    {
        return NETWORK_ERROR;
    }

//Code continues
}



+(NSString*) itemStatus{
    NetworkStatus netStatus = [[Reachability reachabilityForInternetConnection]currentReachabilityStatus];
    if(netStatus == NotReachable)
    {
        return NETWORK_ERROR;
    }


    @try
    {

        DynamoDBGetItemRequest *request = [[DynamoDBGetItemRequest alloc] initWithTableName: TABLE_CONTENT andKey:[[DynamoDBKey alloc] initWithHashKeyElement:
                                                                   [[DynamoDBAttributeValue alloc] initWithS:[ItemHelpClass getItem]]]];

        DynamoDBGetItemResponse *response = [[AmazonClientManager ddb] getItem:request];
        if(response){
            if(((DynamoDBAttributeValue *)[response.item objectForKey:@"UID_ID"]).s){
                return ITEM_BORROWED;
            }
            else{
                return ITEM_NOT_BORROWED;
            }
        }

    }@catch (NSException *exception)
    {
        [AmazonClientManager wipeCredentialsOnAuthError:exception];
    }
    return NETWORK_ERROR;

}

@end

Edit: CPU state

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x200c55c0    r1: 0x432b2b00      r2: 0x00000002      r3: 0x00000020
    r4: 0x00000001    r5: 0x200a2d10      r6: 0x1f5c67f0      r7: 0x2fd95a08
    r8: 0x200a4260    r9: 0x000fc09c     r10: 0x1f5c4c40     r11: 0x200a44e0
    ip: 0x3c33c050    sp: 0x2fd95960      lr: 0x0008928f      pc: 0x3a3c3526
  cpsr: 0x00000030
iphone
objective-c
exc-bad-access
asked on Stack Overflow Mar 21, 2013 by M3rd0n • edited Mar 21, 2013 by Jano

1 Answer

-1
@catch (NSException *exception)
    {
        [AmazonClientManager wipeCredentialsOnAuthError:exception];
        return NULL;
    }
answered on Stack Overflow Mar 21, 2013 by Mr Bonjour

User contributions licensed under CC BY-SA 3.0