Core Data Binary Store crashes when file is locked

Originator:mike.abdullah
Number:rdar://10609036 Date Originated:20-Dec-2011 08:42 PM
Status:Open Resolved:
Product:Mac OS X Product Version:10.7
Classification:Serious Bug Reproducible:Always
 
Summary:
If you ask a NSManagedObjectContext (binary store) to save, and the file has been marked as locked, it crashes with a zombie during error handling. I have attached the Instruments document showing this.

It should open up to show an NSError zombie. It looks like -[NSBinaryObjectStoreFile _writeMetadataData:andMapDataData:toFile:error:] has its own autorelease pool which gets drained, deallocating the error object too early. Something like this:

-(BOOL)_writeMetadataData:(NSData *)metadata andMapDataData:(NSData *)mapData toFile:(NSString *)path error:(NSError **)error;
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  BOOL result = [metadata writeToFile:path options:0 error:error];
  if (!result)
  {
    [pool release];  // deallocates the error object accidentally
    return NO;
  }
  
  // Carry on saving…
}


Thus shortly after, the error is accessed, but no longer exists, so causes a crash.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!