Skip to content

Commit

Permalink
Use ObjC strings instead of C strings to avoid lifetime race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kstenerud committed Feb 26, 2024
1 parent 9af7551 commit 1882fe1
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ @implementation ViewLoadInstrumentationState
classToIsObserved_[[UIViewController class]] = true;
__block auto classToIsObserved = &classToIsObserved_;
__block bool *isEnabled = &isEnabled_;
__block auto appPath = NSBundle.mainBundle.bundlePath.UTF8String;
__block auto appPath = NSBundle.mainBundle.bundlePath;
auto initInstrumentation = ^(id self) {
auto viewControllerClass = [self class];
auto viewControllerBundlePath = [NSBundle bundleForClass: viewControllerClass].bundlePath.UTF8String;
if (strstr(viewControllerBundlePath, appPath)
auto viewControllerBundlePath = [NSBundle bundleForClass: viewControllerClass].bundlePath;
if ([viewControllerBundlePath containsString:appPath]
#if TARGET_OS_SIMULATOR
// and those loaded from BUILT_PRODUCTS_DIR, because Xcode
// doesn't embed them when building for the Simulator.
|| strstr(viewControllerBundlePath, "/DerivedData/")
|| [viewControllerBundlePath containsString:@"/DerivedData/"]
#endif
) {
if (*isEnabled && !isClassObserved(viewControllerClass)) {
Expand Down

0 comments on commit 1882fe1

Please sign in to comment.