diff --git a/src/node_http2.cc b/src/node_http2.cc index 5629298eb94a20..9388e6ef6609b9 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -499,6 +499,8 @@ Http2Session::Http2Session(Environment* env, Http2Session::~Http2Session() { CHECK_EQ(flags_ & SESSION_STATE_HAS_SCOPE, 0); Debug(this, "freeing nghttp2 session"); + for (const auto& stream : streams_) + stream.second->session_ = nullptr; nghttp2_session_del(session_); } @@ -519,7 +521,7 @@ void Http2Stream::EmitStatistics() { Http2StreamPerformanceEntry* entry = new Http2StreamPerformanceEntry(env(), id_, statistics_); env()->SetImmediate([](Environment* env, void* data) { - // This takes ownership, the entr is destroyed at the end of this scope. + // This takes ownership, the entry is destroyed at the end of this scope. std::unique_ptr entry { static_cast(data) }; if (!HasHttp2Observer(env)) @@ -996,7 +998,7 @@ int Http2Session::OnDataChunkReceived(nghttp2_session* handle, // `buf.base == nullptr` is the default Http2StreamListener's way // of saying that it wants a pointer to the raw original. // Since it has access to the original socket buffer from which the data - // was read in the first place, it can use that to minizime ArrayBuffer + // was read in the first place, it can use that to minimize ArrayBuffer // allocations. if (LIKELY(buf.base == nullptr)) buf.base = reinterpret_cast(const_cast(data)); @@ -1336,7 +1338,7 @@ void Http2Session::OnStreamAfterWrite(WriteWrap* w, int status) { } // If the underlying nghttp2_session struct has data pending in its outbound -// queue, MaybeScheduleWrite will schedule a SendPendingData() call to occcur +// queue, MaybeScheduleWrite will schedule a SendPendingData() call to occur // on the next iteration of the Node.js event loop (using the SetImmediate // queue), but only if a write has not already been scheduled. void Http2Session::MaybeScheduleWrite() { @@ -1706,11 +1708,11 @@ Http2Stream::Http2Stream( Http2Stream::~Http2Stream() { + if (session_ == nullptr) + return; Debug(this, "tearing down stream"); - if (session_ != nullptr) { - session_->RemoveStream(this); - session_ = nullptr; - } + session_->RemoveStream(this); + session_ = nullptr; } std::string Http2Stream::diagnostic_name() const { @@ -1785,7 +1787,8 @@ void Http2Stream::Destroy() { // We can destroy the stream now if there are no writes for it // already on the socket. Otherwise, we'll wait for the garbage collector // to take care of cleaning up. - if (!stream->session()->HasWritesOnSocketForStream(stream)) + if (stream->session() == nullptr || + !stream->session()->HasWritesOnSocketForStream(stream)) delete stream; }, this, this->object()); @@ -2177,7 +2180,7 @@ void Http2Session::RefreshSettings(const FunctionCallbackInfo& args) { // A TypedArray instance is shared between C++ and JS land to contain state // information of the current Http2Session. This updates the values in the -// TypedRray so those can be read in JS land. +// TypedArray so those can be read in JS land. void Http2Session::RefreshState(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Http2Session* session; @@ -2510,7 +2513,7 @@ void Http2Session::AltSvc(int32_t id, origin, origin_len, value, value_len), 0); } -// Submits an AltSvc frame to the sent to the connected peer. +// Submits an AltSvc frame to be sent to the connected peer. void Http2Session::AltSvc(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Http2Session* session;