Consistent Crash observed when WKNavigation local variable is getting deallocated

Originator:balaji.iosdev
Number:rdar://43934706 Date Originated:August 31 2018, 4:43 PM
Status:Open Resolved:
Product:iOS Product Version:iOS 11
Classification:WebKit Reproducible:Always
 
Area:
WebKit

Summary:
When `WKNavigation()` is created as a local variable in method, on leaving method observed a crash.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000010831593b WebKit`-[WKNavigation dealloc] + 27
    frame #1: 0x00000001099bca6e libobjc.A.dylib`objc_object::sidetable_release(bool) + 202

Steps to Reproduce:
Execute below piece of code in a playground.
import WebKit
func printWKNavigation() {
    let navigation = WKNavigation()
    print(navigation)
}
printWKNavigation()

Comments

Temporary fix

The following code will swap the problematic dealloc method for one that does nothing. It will leak a little, but it's better than crashing ;)

import

@import WebKit;

  • (void)RM_WKNavigation_dealloc_swizzleFix { Class class = [WKNavigation class];

    SEL originalSelector = NSSelectorFromString(@"dealloc"); SEL swizzledSelector = @selector(RM_WKNavigation_dealloc);

    Method originalMethod = class_getInstanceMethod(class, originalSelector); Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);

    BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));

    if (didAddMethod) { class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); } }

  • (void)RM_WKNavigation_dealloc {

}


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!