diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-10-03 23:44:55 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-10-06 14:26:33 +0300 |
commit | 78e58755f71d7d59901de1c7e2712cebe4de0ef1 (patch) | |
tree | 8b7a55e28352f785718297009975e76517d0b11f /src/stream_base.cc | |
parent | fb2f3cc828e47215ab5dbcc1e5bb911b0cde9e38 (diff) |
http2,tls: store WriteWrap using BaseObjectPtr
Create weak `WriteWrap` and `ShutdownWrap` objects, and when
referencing them in C++ is necessary, use `BaseObjectPtr<>`
instead of plain pointers to keep these objects from being
garbage-collected.
This solves issues that arise when the underlying `StreamBase`
instance is weak, but the `WriteWrap` or `ShutdownWrap` instances
are not; in that case, they would otherwise potentially stick
around in memory after the stream that they originally belong
to is long gone.
It probably makes sense to use `BaseObjectptr<>` more extensively
in `StreamBase` in the long run as well.
PR-URL: https://github.com/nodejs/node/pull/35488
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/stream_base.cc')
-rw-r--r-- | src/stream_base.cc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/stream_base.cc b/src/stream_base.cc index b35df39afe9..3ad20174600 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -621,12 +621,16 @@ StreamResource::~StreamResource() { ShutdownWrap* StreamBase::CreateShutdownWrap( Local<Object> object) { - return new SimpleShutdownWrap<AsyncWrap>(this, object); + auto* wrap = new SimpleShutdownWrap<AsyncWrap>(this, object); + wrap->MakeWeak(); + return wrap; } WriteWrap* StreamBase::CreateWriteWrap( Local<Object> object) { - return new SimpleWriteWrap<AsyncWrap>(this, object); + auto* wrap = new SimpleWriteWrap<AsyncWrap>(this, object); + wrap->MakeWeak(); + return wrap; } } // namespace node |