react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fix use-after-move in console implementation

Open motiz88 opened this issue 1 year ago • 1 comments

Summary: Changelog: [Internal]

In the new CDP backend, calling any console method a second time involves a call to a moved-from std::function. This shouldn't work, but depending on the toolchain, sometimes it does - likely because moving from a std::function leaves it in an unspecified state rather than a definitely empty state, and std::functions are always copyable so falling back to a copy is technically legal.

In the code in question, we're right to want to avoid a copy of the body function into the argument of delegateExecutorSync - only one copy of this function needs to exist at a time. But the correct way to avoid this copy is to capture body by reference, as we can do that repeatedly with no ill effects. (delegateExecutorSync is, as its name suggests, synchronous, so there are no lifetime issues.) Doing this also allows us to remove the use of mutable so the capturing is by const reference.

Differential Revision: D56673529

motiz88 avatar Apr 27 '24 23:04 motiz88

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,461,330 -1
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,834,242 +8
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: e2ad6696d872447608a26fcf499e573280fb43a8 Branch: main

analysis-bot avatar Apr 28 '24 00:04 analysis-bot

Merged as https://github.com/facebook/react-native/commit/fb0c856cf298c6f9310423fb443a6d2c8f3b6252

javache avatar Jun 27 '24 20:06 javache