Skip to content

Commit 9f2fbc2

Browse files
Fix memory leak in TestCallInvoker (#53287)
Summary: Pull Request resolved: #53287 Changelog: [General][Fixed] Fix memory leak in TestCallInvoker This fixes leaks in TestCallInvoker holding onto the jsi::Runtime Reviewed By: lenaic Differential Revision: D80295420 fbshipit-source-id: b14368ccfa86b3bf24b1f84613ec07931bd71a43
1 parent c23e84a commit 9f2fbc2

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

packages/react-native/ReactCommon/callinvoker/ReactCommon/tests/TestCallInvoker.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,27 @@
1010
#include <ReactCommon/CallInvoker.h>
1111
#include <jsi/jsi.h>
1212
#include <list>
13-
#include <memory>
1413

1514
namespace facebook::react {
1615

1716
class TestCallInvoker : public CallInvoker {
1817
public:
19-
explicit TestCallInvoker(std::shared_ptr<facebook::jsi::Runtime> runtime)
18+
explicit TestCallInvoker(facebook::jsi::Runtime& runtime)
2019
: runtime_(runtime) {}
2120

2221
void invokeAsync(CallFunc&& func) noexcept override {
2322
queue_.push_back(std::move(func));
2423
}
2524

2625
void invokeSync(CallFunc&& func) override {
27-
func(*runtime_);
26+
func(runtime_);
2827
}
2928

3029
void flushQueue() {
3130
while (!queue_.empty()) {
32-
queue_.front()(*runtime_);
31+
queue_.front()(runtime_);
3332
queue_.pop_front();
34-
runtime_->drainMicrotasks(); // Run microtasks every cycle.
33+
runtime_.drainMicrotasks(); // Run microtasks every cycle.
3534
}
3635
}
3736

@@ -40,8 +39,8 @@ class TestCallInvoker : public CallInvoker {
4039
}
4140

4241
private:
42+
facebook::jsi::Runtime& runtime_;
4343
std::list<CallFunc> queue_{};
44-
std::shared_ptr<facebook::jsi::Runtime> runtime_{};
4544
};
4645

4746
} // namespace facebook::react

packages/react-native/ReactCommon/react/bridging/tests/BridgingTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BridgingTest : public ::testing::Test {
3131
.withMicrotaskQueue(true)
3232
.build())),
3333
rt(*runtime),
34-
invoker(std::make_shared<TestCallInvoker>(runtime)) {}
34+
invoker(std::make_shared<TestCallInvoker>(*runtime)) {}
3535

3636
~BridgingTest() override {
3737
LongLivedObjectCollection::get(rt).clear();

packages/react-native/ReactCommon/react/nativemodule/core/tests/TurboModuleTestFixture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TurboModuleTestFixture : public ::testing::Test {
2727
public:
2828
explicit TurboModuleTestFixture(Args... args)
2929
: runtime_(hermes::makeHermesRuntime()),
30-
jsInvoker_(std::make_shared<TestCallInvoker>(runtime_)),
30+
jsInvoker_(std::make_shared<TestCallInvoker>(*runtime_)),
3131
module_(std::make_shared<T>(jsInvoker_, std::forward<Args>(args)...)) {}
3232

3333
void SetUp() override {

packages/react-native/ReactCxxPlatform/react/io/tests/NetworkingModuleTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class NetworkingModuleTests : public testing::Test {
2525
protected:
2626
void SetUp() override {
2727
rt_ = facebook::hermes::makeHermesRuntime();
28-
jsInvoker_ = std::make_shared<TestCallInvoker>(rt_);
28+
jsInvoker_ = std::make_shared<TestCallInvoker>(*rt_);
2929
}
3030

3131
static void verifyFormData(

packages/rn-tester/NativeCxxModuleExample/tests/NativeCxxModuleExampleTests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include <NativeCxxModuleExample/NativeCxxModuleExample.h>
9-
#include <ReactCommon/TestCallInvoker.h>
109
#include <ReactCommon/TurboModuleTestFixture.h>
1110
#include <gtest/gtest.h>
1211
#include <list>

0 commit comments

Comments
 (0)