diff options
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r-- | src/stream_base-inl.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index f0d522a7b0..7523b3a545 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -67,8 +67,14 @@ inline void StreamListener::OnStreamAfterWrite(WriteWrap* w, int status) { inline StreamResource::~StreamResource() { while (listener_ != nullptr) { - listener_->OnStreamDestroy(); - RemoveStreamListener(listener_); + StreamListener* listener = listener_; + listener->OnStreamDestroy(); + // Remove the listener if it didn’t remove itself. This makes the logic + // logic in `OnStreamDestroy()` implementations easier, because they + // may call generic cleanup functions which can just remove the + // listener unconditionally. + if (listener == listener_) + RemoveStreamListener(listener_); } } |