Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2021-07-19 12:52:58 +0300
committerAnna Henningsen <anna@addaleax.net>2021-07-22 14:38:20 +0300
commitb6d4e2797a761794e292a664ee92823034c17c88 (patch)
tree2c75b2a5621650abe7caef0355239d63d09b21ec /src/handle_wrap.cc
parent2765f2af79bd8bdfb2f8e5a6473ac1c278521fd4 (diff)
src: close HandleWraps instead of deleting them in OnGCCollect()
When all strong `BaseObjectPtr`s to a `HandleWrap` are gone, we should not delete the `HandleWrap` outright, but instead close it and then delete it only once the libuv close callback has been called. Based on the valgrind output from the issue below, this has a good chance of fixing it. Fixes: https://github.com/nodejs/node/issues/39036 PR-URL: https://github.com/nodejs/node/pull/39441 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/handle_wrap.cc')
-rw-r--r--src/handle_wrap.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc
index d2bd67a5e40..caad0e05546 100644
--- a/src/handle_wrap.cc
+++ b/src/handle_wrap.cc
@@ -85,7 +85,16 @@ void HandleWrap::Close(Local<Value> close_callback) {
void HandleWrap::OnGCCollect() {
- Close();
+ // When all references to a HandleWrap are lost and the object is supposed to
+ // be destroyed, we first call Close() to clean up the underlying libuv
+ // handle. The OnClose callback then acquires and destroys another reference
+ // to that object, and when that reference is lost, we perform the default
+ // action (i.e. destroying `this`).
+ if (state_ != kClosed) {
+ Close();
+ } else {
+ BaseObject::OnGCCollect();
+ }
}