diff --git a/lib/nghttp2_outbound_item.c b/lib/nghttp2_outbound_item.c index 9450ad7c..1633cc36 100644 --- a/lib/nghttp2_outbound_item.c +++ b/lib/nghttp2_outbound_item.c @@ -90,8 +90,6 @@ void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem) { assert(0); break; } - - nghttp2_mem_free(mem, frame->ext.payload); } } } diff --git a/lib/nghttp2_outbound_item.h b/lib/nghttp2_outbound_item.h index ce458a3a..8bda776b 100644 --- a/lib/nghttp2_outbound_item.h +++ b/lib/nghttp2_outbound_item.h @@ -107,6 +107,9 @@ typedef struct nghttp2_outbound_item nghttp2_outbound_item; struct nghttp2_outbound_item { nghttp2_frame frame; + /* Storage for extension frame payload. frame->ext.payload points + to this structure to avoid frequent memory allocation. */ + nghttp2_ext_frame_payload ext_frame_payload; nghttp2_aux_data aux_data; /* The priority used in priority comparion. Smaller is served ealier. For PING, SETTINGS and non-DATA frames (excluding diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index 4aa19470..6329334c 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -470,11 +470,7 @@ int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags _U_, item->aux_data.ext.builtin = 1; - altsvc = nghttp2_mem_malloc(mem, sizeof(nghttp2_ext_altsvc)); - if (altsvc == NULL) { - rv = NGHTTP2_ERR_NOMEM; - goto fail_altsvc_malloc; - } + altsvc = &item->ext_frame_payload.altsvc; frame = &item->frame; frame->ext.payload = altsvc; @@ -485,7 +481,6 @@ int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags _U_, rv = nghttp2_session_add_item(session, item); if (rv != 0) { nghttp2_frame_altsvc_free(&frame->ext, mem); - nghttp2_mem_free(mem, frame->ext.payload); nghttp2_mem_free(mem, item); return rv; @@ -493,8 +488,6 @@ int nghttp2_submit_altsvc(nghttp2_session *session, uint8_t flags _U_, return 0; -fail_altsvc_malloc: - free(item); fail_item_malloc: free(buf);