Skip to content

Commit e5dbc95

Browse files
addaleaxCommit Bot
authored andcommitted
[api] Fix handle leak when getting Context embedder data
The `Context::SlowGetAlignedPointerFromEmbedderData()` method returns a pointer, so the fact that it allocates handles is not obvious to the caller. Since this is the slow path anyway, simply add a handle scope inside of it. The tests are also modified to perform the same check for the `Object` equivalent of this method. Change-Id: I5f03c9a7b70b3a17315609df021606a53c9feb2d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1879902 Reviewed-by: Yang Guo <[email protected]> Commit-Queue: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#64583}
1 parent 1738d99 commit e5dbc95

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/api/api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ void Context::SetEmbedderData(int index, v8::Local<Value> value) {
13121312

13131313
void* Context::SlowGetAlignedPointerFromEmbedderData(int index) {
13141314
const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()";
1315+
HandleScope handle_scope(GetIsolate());
13151316
i::Handle<i::EmbedderDataArray> data =
13161317
EmbedderDataFor(this, index, false, location);
13171318
if (data.is_null()) return nullptr;

test/cctest/test-api.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,8 +2956,11 @@ THREADED_TEST(SetAlignedPointerInInternalFields) {
29562956

29572957
obj->SetAlignedPointerInInternalFields(2, indices, values);
29582958
CcTest::CollectAllGarbage();
2959-
CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0));
2960-
CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1));
2959+
{
2960+
v8::SealHandleScope no_handle_leak(isolate);
2961+
CHECK_EQ(heap_allocated_1, obj->GetAlignedPointerFromInternalField(0));
2962+
CHECK_EQ(heap_allocated_2, obj->GetAlignedPointerFromInternalField(1));
2963+
}
29612964

29622965
indices[0] = 1;
29632966
indices[1] = 0;
@@ -3010,6 +3013,7 @@ THREADED_TEST(EmbedderDataAlignedPointers) {
30103013
}
30113014
CcTest::CollectAllGarbage();
30123015
for (int i = 0; i < 100; i++) {
3016+
v8::SealHandleScope no_handle_leak(env->GetIsolate());
30133017
CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i));
30143018
}
30153019
}

0 commit comments

Comments
 (0)