summaryrefslogtreecommitdiff
path: root/src/stream_base-inl.h
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2018-02-21 15:24:18 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2018-02-21 15:24:18 +0100
commit992703f2b50f6b3483e9b930737d177b9e01256d (patch)
tree7d9b2752b6021d7653d426bbebdc80a437624a47 /src/stream_base-inl.h
parente53275d819fb21d4bb15a27a714f134551233cf9 (diff)
downloadandroid-node-v8-992703f2b50f6b3483e9b930737d177b9e01256d.tar.gz
android-node-v8-992703f2b50f6b3483e9b930737d177b9e01256d.tar.bz2
android-node-v8-992703f2b50f6b3483e9b930737d177b9e01256d.zip
src: prevent persistent handle resource leaks
Replace v8::Persistent with node::Persistent, a specialization that resets the persistent handle on destruction. Prevents accidental resource leaks when forgetting to call .Reset() manually. I'm fairly confident this commit fixes a number of resource leaks that have gone undiagnosed so far. PR-URL: https://github.com/nodejs/node/pull/18656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r--src/stream_base-inl.h26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index b479e04bae..c864feb927 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -225,8 +225,8 @@ inline StreamWriteResult StreamBase::Write(
return StreamWriteResult { async, err, req_wrap };
}
-template<typename OtherBase, bool kResetPersistent>
-SimpleShutdownWrap<OtherBase, kResetPersistent>::SimpleShutdownWrap(
+template <typename OtherBase>
+SimpleShutdownWrap<OtherBase>::SimpleShutdownWrap(
StreamBase* stream,
v8::Local<v8::Object> req_wrap_obj)
: ShutdownWrap(stream, req_wrap_obj),
@@ -236,14 +236,9 @@ SimpleShutdownWrap<OtherBase, kResetPersistent>::SimpleShutdownWrap(
Wrap(req_wrap_obj, static_cast<AsyncWrap*>(this));
}
-template<typename OtherBase, bool kResetPersistent>
-SimpleShutdownWrap<OtherBase, kResetPersistent>::~SimpleShutdownWrap() {
+template <typename OtherBase>
+SimpleShutdownWrap<OtherBase>::~SimpleShutdownWrap() {
ClearWrap(static_cast<AsyncWrap*>(this)->object());
- if (kResetPersistent) {
- auto& persistent = static_cast<AsyncWrap*>(this)->persistent();
- CHECK_EQ(persistent.IsEmpty(), false);
- persistent.Reset();
- }
}
inline ShutdownWrap* StreamBase::CreateShutdownWrap(
@@ -251,8 +246,8 @@ inline ShutdownWrap* StreamBase::CreateShutdownWrap(
return new SimpleShutdownWrap<AsyncWrap>(this, object);
}
-template<typename OtherBase, bool kResetPersistent>
-SimpleWriteWrap<OtherBase, kResetPersistent>::SimpleWriteWrap(
+template <typename OtherBase>
+SimpleWriteWrap<OtherBase>::SimpleWriteWrap(
StreamBase* stream,
v8::Local<v8::Object> req_wrap_obj)
: WriteWrap(stream, req_wrap_obj),
@@ -262,14 +257,9 @@ SimpleWriteWrap<OtherBase, kResetPersistent>::SimpleWriteWrap(
Wrap(req_wrap_obj, static_cast<AsyncWrap*>(this));
}
-template<typename OtherBase, bool kResetPersistent>
-SimpleWriteWrap<OtherBase, kResetPersistent>::~SimpleWriteWrap() {
+template <typename OtherBase>
+SimpleWriteWrap<OtherBase>::~SimpleWriteWrap() {
ClearWrap(static_cast<AsyncWrap*>(this)->object());
- if (kResetPersistent) {
- auto& persistent = static_cast<AsyncWrap*>(this)->persistent();
- CHECK_EQ(persistent.IsEmpty(), false);
- persistent.Reset();
- }
}
inline WriteWrap* StreamBase::CreateWriteWrap(