Find out how to resolve EXC_BAD_ADDRESS KERN_INVALID_ADDRESS when making an attempt to deleteObject from NSManagedContext? (Goal-C iOS)

[ad_1]

I used to be offered with the next challenge within the manufacturing app however not in debug software, thus was not capable of replicate it within the debug software.

I’ve learn up on the next challenge and perceive that it meant one thing has been accomplished to trigger the pointer to be dereferenced and that reminiscence location is not inside on one of many chunks assigned to my program. The pointer used to level to reminiscence was okay, however its chunk was deallocated. (Do appropriate my understanding, if that is incorrect)

I’ve tried varied methods like enabling “Guard Malloc” in xcode or placing in some atmosphere variables

  1. NSAutoreleaseFreedObjectCheckEnabled
  2. NSZombieEnabled
  3. NSDebugEnabled

to additional perceive the error however to no avail.

The next code snippet is the place the error has been thrown:

RSSNewsStorage.m

- (void) deleteAllNewsFeedsOffline:(NSManagedObjectContext *) moc
{
    NSError *error;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    
    NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"SomeEntityName" inManagedObjectContext:moc];
    [fetchRequest setEntity:entityDescription];
    
    NSArray *gadgets = [moc executeFetchRequest:fetchRequest error:&error];
    
    NSLog(@"PRINTING OUT ITEMS %@", gadgets);
    
    for (RSSNewsEntry *managedObject in gadgets) {
        [self deleteNewsImage:managedObject.enclosure];
        NSLog(@"PRINTING OUT managedObject %@", managedObject);
        [moc deleteObject:managedObject];
    }                                                          <--(That is line 41)
}

FetchFeeds

- (void)parseRss:(DDXMLElement *)rootElement entries:(NSMutableArray *)entries {
    dispatch_async([CoredataManager getBackgroundQueue], ^{
        NSManagedObjectContext *moc = [[CoredataManager sharedInstance] workerContext];
        [moc performBlock:^{
            NSArray *channels = [rootElement elementsForName:@"channel"];
            // Insert the information into DB
            NSManagedObjectContext *moc = [Helper mainManagedObjectContext];
            NSEntityDescription *newsEntity = [NSEntityDescription entityForName:@"SomeEntityName" inManagedObjectContext:moc];
            if (channels.depend > 0) {
                [[RSSNewsStorage sharedInstance] deleteAllNewsFeedsOffline:moc];  <--(That is line 140)
            }

The next is the crashlytics error log:

Crashed: NSManagedObjectContext 0x28207e080
0  CoreFoundation                 0x20a78 __CFBasicHashAddValue + 252
1  CoreFoundation                 0x145d0 CFBasicHashAddValue + 2308
2  CoreData                       0x12262c -[NSManagedObjectContext deleteObject:] + 192
3  Share                          0x60dc8 -[RSSNewsStorage deleteAllNewsFeedsOffline:] + 41 (RSSNewsStorage.m:41)
4  Share                          0x70824 __31-[FetchFeeds parseRss:entries:]_block_invoke_2 + 140 (FetchFeeds.m:140)
5  CoreData                       0x1f834 developerSubmittedBlockToNSManagedObjectContextPerform + 156
6  libdispatch.dylib              0x3a2c _dispatch_client_callout + 20
7  libdispatch.dylib              0xb124 _dispatch_lane_serial_drain + 668
8  libdispatch.dylib              0xbc80 _dispatch_lane_invoke + 392
9  libdispatch.dylib              0x16500 _dispatch_workloop_worker_thread + 648
10 libsystem_pthread.dylib        0x10bc _pthread_wqthread + 288
11 libsystem_pthread.dylib        0xe5c start_wqthread + 8

[ad_2]

Leave a Reply