Free HTTP headers and post data memory in disconnect and DNS failure callback (#1403)

This commit is contained in:
Arnim Läuger 2016-07-17 22:27:26 +02:00 committed by Marcel Stör
parent cc2fee5ec0
commit b21b3e08aa
1 changed files with 18 additions and 8 deletions

View File

@ -233,6 +233,22 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
HTTPCLIENT_DEBUG( "Sending request header\n" ); 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 ) 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 ); req->callback_handle( body, http_status, req->buffer );
} }
if (req->buffer) { http_free_req( req );
os_free( req->buffer );
}
os_free( req->hostname );
os_free( req->method );
os_free( req->path );
os_free( req );
} }
/* Fix memory leak. */ /* Fix memory leak. */
espconn_delete( conn ); espconn_delete( conn );
@ -354,7 +364,7 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
{ {
req->callback_handle( "", -1, "" ); req->callback_handle( "", -1, "" );
} }
os_free( req ); http_free_req( req );
} }
else else
{ {