diff --git a/src/node_http2.cc b/src/node_http2.cc index 67306e1f4db3e3..9811c94c329d0d 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1137,8 +1137,7 @@ inline void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { if (stream->IsDestroyed()) return; - nghttp2_header* headers = stream->headers(); - size_t count = stream->headers_count(); + std::vector headers(stream->move_headers()); Local name_str; Local value_str; @@ -1155,9 +1154,9 @@ inline void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { // this way for performance reasons (it's faster to generate and pass an // array than it is to generate and pass the object). size_t n = 0; - while (count > 0) { + while (n < headers.size()) { size_t j = 0; - while (count > 0 && j < arraysize(argv) / 2) { + while (n < headers.size() && j < arraysize(argv) / 2) { nghttp2_header item = headers[n++]; // The header name and value are passed as external one-byte strings name_str = @@ -1166,7 +1165,6 @@ inline void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { ExternalHeader::New(env(), item.value).ToLocalChecked(); argv[j * 2] = name_str; argv[j * 2 + 1] = value_str; - count--; j++; } // For performance, we pass name and value pairs to array.protototype.push @@ -1782,6 +1780,11 @@ Http2Stream::Http2Stream( Http2Stream::~Http2Stream() { + for (nghttp2_header& header : current_headers_) { + nghttp2_rcbuf_decref(header.name); + nghttp2_rcbuf_decref(header.value); + } + if (session_ == nullptr) return; DEBUG_HTTP2STREAM(this, "tearing down stream"); diff --git a/src/node_http2.h b/src/node_http2.h index 67af832eff78b7..a35dbf468afa43 100644 --- a/src/node_http2.h +++ b/src/node_http2.h @@ -653,18 +653,14 @@ class Http2Stream : public AsyncWrap, nghttp2_rcbuf* value, uint8_t flags); - inline nghttp2_header* headers() { - return current_headers_.data(); + inline std::vector move_headers() { + return std::move(current_headers_); } inline nghttp2_headers_category headers_category() const { return current_headers_category_; } - inline size_t headers_count() const { - return current_headers_.size(); - } - void StartHeaders(nghttp2_headers_category category); // Required for StreamBase