Skip to content

fix(ios): prevent app crash in Release builds#286

Merged
thomson-t merged 1 commit intomainfrom
fix/ios-release-build-crash
Mar 5, 2026
Merged

fix(ios): prevent app crash in Release builds#286
thomson-t merged 1 commit intomainfrom
fix/ios-release-build-crash

Conversation

@thomson-t
Copy link
Contributor

Summary

The TurboModule bridge passes a null C++ reference when JS omits the optional roktConfig parameter. The existing guard &roktConfig != nullptr is undefined behavior in C++ — the compiler is permitted to assume a reference is never null and remove the check entirely. In Debug builds (-O0) the check survives by accident, so selectPlacements works when run from Xcode. In Release builds (-O2) the compiler optimizes the check away, and the subsequent call to roktConfig.cacheConfig() dereferences address 0x0, producing EXC_BAD_ACCESS (SIGSEGV) on the com.meta.react.turbomodulemanager.queue thread.
Because the crash occurs on a background dispatch queue, the placement silently fails to appear with no visible error — partners report "selectPlacements does nothing" rather than a crash. Extracted the roktConfig dictionary conversion into a standalone static function annotated with attribute((optnone)) to prevent the compiler from applying UB-based optimizations, ensuring the null reference check is preserved in all build configurations.

Testing Plan

{explain how this has been tested, and what additional testing should be done}

Master Issue

Closes https://go.mparticle.com/work/REPLACEME

The TurboModule bridge passes a null C++ reference when JS omits the
optional roktConfig parameter. The existing guard `&roktConfig != nullptr`
is undefined behavior in C++ — the compiler is permitted to assume a
reference is never null and remove the check entirely.
In Debug builds (-O0) the check survives by accident, so selectPlacements
works when run from Xcode. In Release builds (-O2) the compiler optimizes
the check away, and the subsequent call to roktConfig.cacheConfig()
dereferences address 0x0, producing EXC_BAD_ACCESS (SIGSEGV) on the
com.meta.react.turbomodulemanager.queue thread.
Because the crash occurs on a background dispatch queue, the placement
silently fails to appear with no visible error — partners report
"selectPlacements does nothing" rather than a crash.
Extracted the roktConfig dictionary conversion into a standalone static
function annotated with __attribute__((optnone)) to prevent the compiler
from applying UB-based optimizations, ensuring the null reference check
is preserved in all build configurations.
@thomson-t thomson-t requested a review from a team as a code owner March 5, 2026 19:06
Copilot AI review requested due to automatic review settings March 5, 2026 19:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@thomson-t thomson-t merged commit 6640d6b into main Mar 5, 2026
10 checks passed
@thomson-t thomson-t deleted the fix/ios-release-build-crash branch March 5, 2026 19:33
@rokt-releases rokt-releases bot mentioned this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants