From b21b3e08aad633ccfd5fd29066400a06bb699ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Sun, 17 Jul 2016 22:27:26 +0200 Subject: [PATCH] Free HTTP headers and post data memory in disconnect and DNS failure callback (#1403) --- app/http/httpclient.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/http/httpclient.c b/app/http/httpclient.c index 75d0e4a8..0868bf9d 100644 --- a/app/http/httpclient.c +++ b/app/http/httpclient.c @@ -233,6 +233,22 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg ) HTTPCLIENT_DEBUG( "Sending request header\n" ); } +static void http_free_req( request_args_t * req) +{ + if (req->buffer) { + os_free( req->buffer ); + } + if (req->post_data) { + os_free( req->post_data ); + } + if (req->headers) { + os_free( req->headers ); + } + os_free( req->hostname ); + os_free( req->method ); + os_free( req->path ); + os_free( req ); +} static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg ) { @@ -301,13 +317,7 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg ) { req->callback_handle( body, http_status, req->buffer ); } - if (req->buffer) { - os_free( req->buffer ); - } - os_free( req->hostname ); - os_free( req->method ); - os_free( req->path ); - os_free( req ); + http_free_req( req ); } /* Fix memory leak. */ espconn_delete( conn ); @@ -354,7 +364,7 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_ { req->callback_handle( "", -1, "" ); } - os_free( req ); + http_free_req( req ); } else {