diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index f9444e09..83191211 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -544,7 +544,8 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags, uint8_t *name, return 0; fail2: - if (flags & NGHTTP2_HD_FLAG_NAME_ALLOC) { + if ((flags & NGHTTP2_HD_FLAG_NAME_ALLOC) && + (flags & NGHTTP2_HD_FLAG_NAME_GIFT) == 0) { nghttp2_mem_free(mem, ent->nv.name); } fail: @@ -1894,7 +1895,11 @@ static int hd_inflate_commit_indname(nghttp2_hd_inflater *inflater, return 0; } - nghttp2_mem_free(mem, nv.value); + if (inflater->index < NGHTTP2_STATIC_TABLE_LENGTH) { + nghttp2_mem_free(mem, nv.value); + } else { + nghttp2_mem_free(mem, nv.name); + } return NGHTTP2_ERR_NOMEM; } diff --git a/tests/failmalloc_test.c b/tests/failmalloc_test.c index 42062d38..55fe9838 100644 --- a/tests/failmalloc_test.c +++ b/tests/failmalloc_test.c @@ -458,13 +458,14 @@ static void run_nghttp2_hd(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; int rv; - nghttp2_nv nva1[] = {MAKE_NV(":scheme", "https"), - MAKE_NV(":authority", "example.org"), - MAKE_NV(":path", "/slashdot"), - MAKE_NV("accept-encoding", "gzip, deflate")}; + nghttp2_nv nva1[] = { + MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"), + MAKE_NV(":path", "/slashdot"), + MAKE_NV("accept-encoding", "gzip, deflate"), MAKE_NV("foo", "bar")}; nghttp2_nv nva2[] = { MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"), - MAKE_NV(":path", "/style.css"), MAKE_NV("cookie", "nghttp2=FTW")}; + MAKE_NV(":path", "/style.css"), MAKE_NV("cookie", "nghttp2=FTW"), + MAKE_NV("foo", "bar2")}; rv = frame_pack_bufs_init(&bufs);