From 5d9924ae5d6b8969e59b85649906aa7bcb7480f9 Mon Sep 17 00:00:00 2001 From: xushuangqing Date: Sun, 23 Aug 2020 20:09:48 +0800 Subject: [PATCH] Fix a crash caused by private class _PFResultASCIIString in iOS 14 --- .../Graph/FBObjectiveCGraphElement.mm | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm b/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm index 648add9..5295a18 100644 --- a/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm +++ b/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm @@ -7,6 +7,7 @@ */ #import "FBObjectiveCGraphElement+Internal.h" +#import #import #import @@ -39,22 +40,22 @@ - (instancetype)initWithObject:(id)object { if (self = [super init]) { #if _INTERNAL_RCD_ENABLED - // We are trying to mimic how ObjectiveC does storeWeak to not fall into - // _objc_fatal path - // https://github.com/bavarious/objc4/blob/3f282b8dbc0d1e501f97e4ed547a4a99cb3ac10b/runtime/objc-weak.mm#L369 - - Class aCls = object_getClass(object); - - BOOL (*allowsWeakReference)(id, SEL) = - (__typeof__(allowsWeakReference))class_getMethodImplementation(aCls, @selector(allowsWeakReference)); - - if (allowsWeakReference && (IMP)allowsWeakReference != _objc_msgForward) { - if (allowsWeakReference(object, @selector(allowsWeakReference))) { - // This is still racey since allowsWeakReference could change it value by now. + malloc_zone_t *zone = malloc_zone_from_ptr((__bridge void *)object); + if (zone) { + // We are trying to mimic how ObjectiveC does storeWeak to not fall into + // _objc_fatal path + // https://github.com/bavarious/objc4/blob/3f282b8dbc0d1e501f97e4ed547a4a99cb3ac10b/runtime/objc-weak.mm#L369 + Class aCls = object_getClass(object); + BOOL (*allowsWeakReference)(id, SEL) = + (__typeof__(allowsWeakReference))class_getMethodImplementation(aCls, @selector(allowsWeakReference)); + if (allowsWeakReference && (IMP)allowsWeakReference != _objc_msgForward) { + if (allowsWeakReference(object, @selector(allowsWeakReference))) { + // This is still racey since allowsWeakReference could change it value by now. + _object = object; + } + } else { _object = object; } - } else { - _object = object; } #endif _namePath = namePath;