From 490b233daf47485ba6f9d6bd7fd2d7685afc34b2 Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Mon, 25 Feb 2013 10:42:42 -0500 Subject: [PATCH] Add countermeasure to avoid crash in `cxx_destruct` during deallocation of mapping result --- Code/Network/RKManagedObjectRequestOperation.m | 11 +++++++++++ Code/Network/RKObjectRequestOperation.h | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Code/Network/RKManagedObjectRequestOperation.m b/Code/Network/RKManagedObjectRequestOperation.m index 3d9cb1b0cc..07cf12d74e 100644 --- a/Code/Network/RKManagedObjectRequestOperation.m +++ b/Code/Network/RKManagedObjectRequestOperation.m @@ -315,6 +315,17 @@ - (id)initWithHTTPRequestOperation:(RKHTTPRequestOperation *)requestOperation re return self; } +/** + NOTE: This dealloc implementation attempts to avoid crashes coming from Core Data due to the ordering of deallocations under ARC. If the MOC is deallocated before its managed objects, it can trigger a crash. We dispose of the mapping result and reset the private context to avoid this situation. The crash manifests itself in `cxx_destruct` + [sbw - 2/25/2013] + */ +- (void)dealloc +{ + _mappingResult = nil; + _responseMapperOperation = nil; + _privateContext = nil; +} + - (void)setTargetObject:(id)targetObject { [super setTargetObject:targetObject]; diff --git a/Code/Network/RKObjectRequestOperation.h b/Code/Network/RKObjectRequestOperation.h index e43c33c12e..227017307e 100644 --- a/Code/Network/RKObjectRequestOperation.h +++ b/Code/Network/RKObjectRequestOperation.h @@ -62,7 +62,10 @@ @see `RKMIMETypeSerialization` @see `RKManagedObjectRequestOperation` */ -@interface RKObjectRequestOperation : NSOperation +@interface RKObjectRequestOperation : NSOperation { + @protected + RKMappingResult *_mappingResult; +} ///----------------------------------------------- /// @name Initializing an Object Request Operation