From ce1bf11d4bbb0d7b44659d68aef61d2160b54b7d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 18 Dec 2014 21:02:44 +0900 Subject: [PATCH] Fix memory leak --- lib/nghttp2_hd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index a7c6ab74..6e5662be 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -785,11 +785,18 @@ static nghttp2_hd_entry *add_hd_table_incremental(nghttp2_hd_context *context, if (rv != 0) { --new_ent->ref; - /* nv->name and nv->value are managed by caller. */ - new_ent->nv.name = NULL; - new_ent->nv.namelen = 0; - new_ent->nv.value = NULL; - new_ent->nv.valuelen = 0; + if ((entry_flags & NGHTTP2_HD_FLAG_NAME_ALLOC) && + (entry_flags & NGHTTP2_HD_FLAG_NAME_GIFT)) { + /* nv->name are managed by caller. */ + new_ent->nv.name = NULL; + new_ent->nv.namelen = 0; + } + if ((entry_flags & NGHTTP2_HD_FLAG_VALUE_ALLOC) && + (entry_flags & NGHTTP2_HD_FLAG_VALUE_GIFT)) { + /* nv->value are managed by caller. */ + new_ent->nv.value = NULL; + new_ent->nv.valuelen = 0; + } nghttp2_hd_entry_free(new_ent, mem); nghttp2_mem_free(mem, new_ent);