From 4ca137b59bc6aaa25f8b14db2bdd2e72c43502e5 Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Tue, 10 Oct 2023 00:33:06 +0900 Subject: [PATCH] Reallocate a buffer for H2 header block only if needed (#10568) Co-authored-by: Bryan Call (cherry picked from commit 65dd18632648e5441df115c4ed666af02e61d2d9) --- proxy/http2/Http2ConnectionState.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index 888fdc39b5d..dcfab9b6747 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -937,8 +937,10 @@ rcv_continuation_frame(Http2ConnectionState &cstate, const Http2Frame &frame) "header blocks too large"); } - stream->header_blocks = static_cast(ats_realloc(stream->header_blocks, stream->header_blocks_length)); - frame.reader()->memcpy(stream->header_blocks + header_blocks_offset, payload_length); + if (payload_length > 0) { + stream->header_blocks = static_cast(ats_realloc(stream->header_blocks, stream->header_blocks_length)); + frame.reader()->memcpy(stream->header_blocks + header_blocks_offset, payload_length); + } if (frame.header().flags & HTTP2_FLAGS_HEADERS_END_HEADERS) { // NOTE: If there are END_HEADERS flag, decode stored Header Blocks.