From 08603e565bca3a64cf70b46b2b8cd8412fda37b7 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 24 Mar 2017 15:49:19 +0100 Subject: [PATCH] winhttp: Fix a memory leak in insert_header (Valgrind). Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/winhttp/request.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index b2b72c7ccb8..3cdb6abaef9 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -368,25 +368,21 @@ static int get_header_index( request_t *request, LPCWSTR field, int requested_in static BOOL insert_header( request_t *request, header_t *header ) { - DWORD count; + DWORD count = request->num_headers + 1; header_t *hdrs; - count = request->num_headers + 1; - if (count > 1) + if (request->headers) hdrs = heap_realloc_zero( request->headers, sizeof(header_t) * count ); else - hdrs = heap_alloc_zero( sizeof(header_t) * count ); + hdrs = heap_alloc_zero( sizeof(header_t) ); + if (!hdrs) return FALSE; - if (hdrs) - { - request->headers = hdrs; - request->headers[count - 1].field = strdupW( header->field ); - request->headers[count - 1].value = strdupW( header->value ); - request->headers[count - 1].is_request = header->is_request; - request->num_headers++; - return TRUE; - } - return FALSE; + request->headers = hdrs; + request->headers[count - 1].field = strdupW( header->field ); + request->headers[count - 1].value = strdupW( header->value ); + request->headers[count - 1].is_request = header->is_request; + request->num_headers = count; + return TRUE; } static BOOL delete_header( request_t *request, DWORD index )