Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 75ae77d

Browse filesBrowse files
committed
src: do not access Environment-owned handles after cleanup
Do not access handles that have already begun to be closed or are closed. PR-URL: #26256 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 74d11e7 commit 75ae77d
Copy full SHA for 75ae77d

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ void Environment::RegisterHandleCleanups() {
398398
void* arg) {
399399
handle->data = env;
400400

401-
env->CloseHandle(handle, [](uv_handle_t* handle) {});
401+
env->CloseHandle(handle, [](uv_handle_t* handle) {
402+
#ifdef DEBUG
403+
memset(handle, 0xab, uv_handle_size(handle->type));
404+
#endif
405+
});
402406
};
403407

404408
RegisterHandleCleanup(
@@ -512,6 +516,7 @@ void Environment::PrintSyncTrace() const {
512516
}
513517

514518
void Environment::RunCleanup() {
519+
started_cleanup_ = true;
515520
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
516521
"RunCleanup", this);
517522
CleanupHandles();
@@ -660,10 +665,13 @@ void Environment::RunAndClearNativeImmediates() {
660665

661666

662667
void Environment::ScheduleTimer(int64_t duration_ms) {
668+
if (started_cleanup_) return;
663669
uv_timer_start(timer_handle(), RunTimers, duration_ms, 0);
664670
}
665671

666672
void Environment::ToggleTimerRef(bool ref) {
673+
if (started_cleanup_) return;
674+
667675
if (ref) {
668676
uv_ref(reinterpret_cast<uv_handle_t*>(timer_handle()));
669677
} else {
@@ -763,6 +771,8 @@ void Environment::CheckImmediate(uv_check_t* handle) {
763771
}
764772

765773
void Environment::ToggleImmediateRef(bool ref) {
774+
if (started_cleanup_) return;
775+
766776
if (ref) {
767777
// Idle handle is needed only to stop the event loop from blocking in poll.
768778
uv_idle_start(immediate_idle_handle(), [](uv_idle_t*){ });
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ class Environment {
11771177
CleanupHookCallback::Hash,
11781178
CleanupHookCallback::Equal> cleanup_hooks_;
11791179
uint64_t cleanup_hook_counter_ = 0;
1180+
bool started_cleanup_ = false;
11801181

11811182
static void EnvPromiseHook(v8::PromiseHookType type,
11821183
v8::Local<v8::Promise> promise,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.