src: add consistency check to node_platform.cc
We use the `Isolate*` pointer as the sole identifier for a V8 Isolate. In some environments (e.g. multi-threaded), Isolates may be destroyed and new ones created; then, it may happen that the memory that was previously used for one `Isolate` can be re-used for another `Isolate` after the first one has been disposed of. This check is a little guard against accidentally re-using the same per-Isolate platform data structure in such cases, i.e. making sure (to the degree to which that is possible) that the old `Isolate*` has been properly unregistered before one at the same memory address is added. (It’s not 100 % foolproof because the `uv_loop_t*` pointer value could theoretically be the same as well.) PR-URL: https://github.com/nodejs/node/pull/21156 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
977d0111b5
commit
505bfdc7e4
@ -141,6 +141,7 @@ void NodePlatform::RegisterIsolate(IsolateData* isolate_data, uv_loop_t* loop) {
|
|||||||
Mutex::ScopedLock lock(per_isolate_mutex_);
|
Mutex::ScopedLock lock(per_isolate_mutex_);
|
||||||
std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate];
|
std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate];
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
CHECK_EQ(loop, existing->event_loop());
|
||||||
existing->ref();
|
existing->ref();
|
||||||
} else {
|
} else {
|
||||||
per_isolate_[isolate] =
|
per_isolate_[isolate] =
|
||||||
|
@ -72,6 +72,8 @@ class PerIsolatePlatformData :
|
|||||||
bool FlushForegroundTasksInternal();
|
bool FlushForegroundTasksInternal();
|
||||||
void CancelPendingDelayedTasks();
|
void CancelPendingDelayedTasks();
|
||||||
|
|
||||||
|
const uv_loop_t* event_loop() const { return loop_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DeleteFromScheduledTasks(DelayedTask* task);
|
void DeleteFromScheduledTasks(DelayedTask* task);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user