From a92e260f17574fbb4f3df08bd3ca33c784bcb919 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Wed, 28 Dec 2016 20:06:16 +0100 Subject: [PATCH] All freed pointers are NULLed --- include/libhttp.h | 2 +- src/httplib_check_acl.c | 2 +- src/httplib_close_all_listening_sockets.c | 7 +--- src/httplib_close_connection.c | 6 +-- src/httplib_closedir.c | 2 +- src/httplib_config_options.c | 1 - src/httplib_connect_client.c | 9 ++--- src/httplib_connect_websocket_client.c | 22 +++++------ src/httplib_dir_scan_callback.c | 2 +- src/httplib_event_queue.c | 6 +-- src/httplib_free_context.c | 47 ++++++++--------------- src/httplib_handle_cgi_request.c | 6 +-- src/httplib_handle_directory_request.c | 4 +- src/httplib_handle_form_request.c | 5 +-- src/httplib_main.h | 2 +- src/httplib_malloc.c | 11 ++++-- src/httplib_opendir.c | 5 +-- src/httplib_read_websocket.c | 2 +- src/httplib_set_handler_type.c | 9 +++-- src/httplib_start.c | 14 +++---- src/httplib_timer.c | 2 +- src/httplib_tls_dtor.c | 2 +- src/httplib_uninitialize_ssl.c | 3 +- src/httplib_vprintf.c | 4 +- src/httplib_websocket_client_thread.c | 2 +- src/httplib_websocket_client_write.c | 4 +- src/httplib_worker_thread.c | 16 ++++---- 27 files changed, 88 insertions(+), 109 deletions(-) diff --git a/include/libhttp.h b/include/libhttp.h index 850aaf40..3933dc91 100644 --- a/include/libhttp.h +++ b/include/libhttp.h @@ -933,7 +933,7 @@ typedef void (*httplib_alloc_callback_func)( const char *file, unsigned line, co #define httplib_realloc(a, b) XX_httplib_realloc_ex(a, b, __FILE__, __LINE__) LIBHTTP_API void * XX_httplib_calloc_ex( size_t count, size_t size, const char *file, unsigned line ); -LIBHTTP_API void XX_httplib_free_ex( void *memory, const char *file, unsigned line ); +LIBHTTP_API void * XX_httplib_free_ex( void *memory, const char *file, unsigned line ); LIBHTTP_API void * XX_httplib_malloc_ex( size_t size, const char *file, unsigned line ); LIBHTTP_API void * XX_httplib_realloc_ex( void *memory, size_t newsize, const char *file, unsigned line ); diff --git a/src/httplib_check_acl.c b/src/httplib_check_acl.c index 1dcbf1ee..28d57159 100644 --- a/src/httplib_check_acl.c +++ b/src/httplib_check_acl.c @@ -47,7 +47,7 @@ int XX_httplib_check_acl( struct httplib_context *ctx, uint32_t remote_ip ) { if ( ctx == NULL ) return -1; - list = ctx->cfg[ACCESS_CONTROL_LIST]; + list = ctx->access_control_list; if ( list == NULL ) allowed = '+'; else allowed = '-'; diff --git a/src/httplib_close_all_listening_sockets.c b/src/httplib_close_all_listening_sockets.c index 369498aa..e137e70c 100644 --- a/src/httplib_close_all_listening_sockets.c +++ b/src/httplib_close_all_listening_sockets.c @@ -46,10 +46,7 @@ void XX_httplib_close_all_listening_sockets( struct httplib_context *ctx ) { ctx->listening_sockets[i].sock = INVALID_SOCKET; } - httplib_free( ctx->listening_sockets ); - httplib_free( ctx->listening_socket_fds ); - - ctx->listening_sockets = NULL; - ctx->listening_socket_fds = NULL; + ctx->listening_sockets = httplib_free( ctx->listening_sockets ); + ctx->listening_socket_fds = httplib_free( ctx->listening_socket_fds ); } /* XX_close_all_listening_sockets */ diff --git a/src/httplib_close_connection.c b/src/httplib_close_connection.c index a9a20e68..55f627a7 100644 --- a/src/httplib_close_connection.c +++ b/src/httplib_close_connection.c @@ -124,12 +124,12 @@ void httplib_close_connection( struct httplib_connection *conn ) { if ( client_ctx->workerthreadids[i] != 0 ) httplib_pthread_join( client_ctx->workerthreadids[i], NULL ); } - httplib_free( client_ctx->workerthreadids ); - httplib_free( client_ctx ); + client_ctx->workerthreadids = httplib_free( client_ctx->workerthreadids ); + client_ctx = httplib_free( client_ctx ); httplib_pthread_mutex_destroy( & conn->mutex ); - httplib_free( conn ); + conn = httplib_free( conn ); } } /* httplib_close_connection */ diff --git a/src/httplib_closedir.c b/src/httplib_closedir.c index ffc18f1d..27c2e713 100644 --- a/src/httplib_closedir.c +++ b/src/httplib_closedir.c @@ -46,7 +46,7 @@ LIBHTTP_API int httplib_closedir( DIR *dir ) { if ( dir != NULL ) { if ( dir->handle != INVALID_HANDLE_VALUE ) result = ( FindClose( dir->handle ) ) ? 0 : -1; - httplib_free( dir ); + dir = httplib_free( dir ); } else { diff --git a/src/httplib_config_options.c b/src/httplib_config_options.c index fd1938a2..93ad12de 100644 --- a/src/httplib_config_options.c +++ b/src/httplib_config_options.c @@ -39,7 +39,6 @@ struct httplib_option XX_httplib_config_options[] = { { "ssi_pattern", CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$" }, { "global_auth_file", CONFIG_TYPE_FILE, NULL }, { "index_files", CONFIG_TYPE_STRING, "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php" }, - { "access_control_list", CONFIG_TYPE_STRING, NULL }, { "listening_ports", CONFIG_TYPE_STRING, "8080" }, { "document_root", CONFIG_TYPE_DIRECTORY, NULL }, { "ssl_certificate", CONFIG_TYPE_FILE, NULL }, diff --git a/src/httplib_connect_client.c b/src/httplib_connect_client.c index 13f1cde6..fe7c9ad1 100644 --- a/src/httplib_connect_client.c +++ b/src/httplib_connect_client.c @@ -97,8 +97,7 @@ static struct httplib_connection *httplib_connect_client_impl( const struct http XX_httplib_snprintf( NULL, NULL, ebuf, ebuf_len, "SSL_CTX_new error" ); closesocket( sock ); - httplib_free( conn ); - conn = NULL; + conn = httplib_free( conn ); } #endif /* NO_SSL */ @@ -140,8 +139,7 @@ static struct httplib_connection *httplib_connect_client_impl( const struct http XX_httplib_snprintf( NULL, NULL, ebuf, ebuf_len, "Can not use SSL client certificate" ); SSL_CTX_free( conn->client_ssl_ctx ); closesocket( sock ); - httplib_free( conn ); - conn = NULL; + conn = httplib_free( conn ); } } @@ -158,8 +156,7 @@ static struct httplib_connection *httplib_connect_client_impl( const struct http XX_httplib_snprintf( NULL, NULL, ebuf, ebuf_len, "SSL connection error" ); SSL_CTX_free( conn->client_ssl_ctx ); closesocket( sock ); - httplib_free( conn ); - conn = NULL; + conn = httplib_free( conn ); } } #endif diff --git a/src/httplib_connect_websocket_client.c b/src/httplib_connect_websocket_client.c index d95236d3..70dbe73f 100644 --- a/src/httplib_connect_websocket_client.c +++ b/src/httplib_connect_websocket_client.c @@ -86,7 +86,7 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i XX_httplib_snprintf( conn, NULL, error_buffer, error_buffer_size, "Unexpected server reply" ); } - if ( conn != NULL ) httplib_free( conn ); + if ( conn != NULL ) conn = httplib_free( conn ); return NULL; } @@ -96,7 +96,7 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i */ newctx = httplib_malloc( sizeof(struct httplib_context) ); - if ( newctx == NULL ) { httplib_free( conn ); return NULL; } + if ( newctx == NULL ) { conn = httplib_free( conn ); return NULL; } *newctx = *conn->ctx; newctx->user_data = user_data; @@ -106,8 +106,8 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i if ( newctx->workerthreadids == NULL ) { - httplib_free( newctx ); - httplib_free( conn ); + newctx = httplib_free( newctx ); + conn = httplib_free( conn ); return NULL; } @@ -117,9 +117,9 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i if ( thread_data == NULL ) { - httplib_free( newctx->workerthreadids ); - httplib_free( newctx ); - httplib_free( conn ); + newctx->workerthreadids = httplib_free( newctx->workerthreadids ); + newctx = httplib_free( newctx ); + conn = httplib_free( conn ); return NULL; } @@ -137,10 +137,10 @@ struct httplib_connection *httplib_connect_websocket_client( const char *host, i if ( XX_httplib_start_thread_with_id( XX_httplib_websocket_client_thread, thread_data, newctx->workerthreadids) != 0 ) { - httplib_free( thread_data ); - httplib_free( newctx->workerthreadids ); - httplib_free( newctx ); - httplib_free( conn ); + thread_data = httplib_free( thread_data ); + newctx->workerthreadids = httplib_free( newctx->workerthreadids ); + newctx = httplib_free( newctx ); + conn = httplib_free( conn ); return NULL; } diff --git a/src/httplib_dir_scan_callback.c b/src/httplib_dir_scan_callback.c index 2850f84f..80ca7b27 100644 --- a/src/httplib_dir_scan_callback.c +++ b/src/httplib_dir_scan_callback.c @@ -41,7 +41,7 @@ void XX_httplib_dir_scan_callback( struct de *de, void *data ) { old_entries = dsd->entries; dsd->entries = httplib_realloc( old_entries, dsd->arr_size * sizeof(dsd->entries[0]) ); - if ( dsd->entries == NULL && old_entries != NULL ) httplib_free( old_entries ); + if ( dsd->entries == NULL && old_entries != NULL ) old_entries = httplib_free( old_entries ); } if ( dsd->entries == NULL ) { diff --git a/src/httplib_event_queue.c b/src/httplib_event_queue.c index 7142da17..d859638a 100644 --- a/src/httplib_event_queue.c +++ b/src/httplib_event_queue.c @@ -118,7 +118,7 @@ void *event_create(void) { * pthread mutex not available */ - XX_httplib_free( ret ); + ret = httplib_free( ret ); return NULL; } if ( httplib_pthread_cond_init( & ret->cond, NULL ) != 0 ) { @@ -128,7 +128,7 @@ void *event_create(void) { */ httplib_pthread_mutex_destroy( & ret->mutex ); - XX_httplib_free( ret ); + ret = httplib_free( ret ); return NULL; } @@ -176,7 +176,7 @@ void event_destroy( void *eventhdl ) { httplib_pthread_cond_destroy( & ev->cond ); httplib_pthread_mutex_destroy( & ev->mutex ); - XX_httplib_free( ev ); + ev = httplib_free( ev ); } /* event_destroy */ diff --git a/src/httplib_free_context.c b/src/httplib_free_context.c index 432b352f..4fa82981 100644 --- a/src/httplib_free_context.c +++ b/src/httplib_free_context.c @@ -53,18 +53,12 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { httplib_pthread_mutex_destroy( & ctx->thread_mutex ); #if defined(ALTERNATIVE_QUEUE) - if ( ctx->client_socks != NULL ) { - - XX_httplib_free( ctx->client_socks ); - ctx->client_socks = NULL; - } + if ( ctx->client_socks != NULL ) ctx->client_socks = httplib_free( ctx->client_socks ); if ( ctx->client_wait_events != NULL ) { for (i=0; (unsigned)i < ctx->cfg_worker_threads; i++) event_destroy( ctx->client_wait_events[i] ); - XX_httplib_free( ctx->client_wait_events ); - - ctx->client_wait_events = NULL; + ctx->client_wait_events = httplib_free( ctx->client_wait_events ); } #else httplib_pthread_cond_destroy( & ctx->sq_empty ); @@ -85,22 +79,19 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { * Deallocate config parameters */ - if ( ctx->access_log_file != NULL ) { httplib_free( ctx->access_log_file ); ctx->access_log_file = NULL; } - if ( ctx->cgi_environment != NULL ) { httplib_free( ctx->cgi_environment ); ctx->cgi_environment = NULL; } - if ( ctx->error_log_file != NULL ) { httplib_free( ctx->error_log_file ); ctx->error_log_file = NULL; } - if ( ctx->extra_mime_types != NULL ) { httplib_free( ctx->extra_mime_types ); ctx->extra_mime_types = NULL; } - if ( ctx->protect_uri != NULL ) { httplib_free( ctx->protect_uri ); ctx->protect_uri = NULL; } - if ( ctx->run_as_user != NULL ) { httplib_free( ctx->run_as_user ); ctx->run_as_user = NULL; } - if ( ctx->ssl_cipher_list != NULL ) { httplib_free( ctx->ssl_cipher_list ); ctx->ssl_cipher_list = NULL; } - if ( ctx->throttle != NULL ) { httplib_free( ctx->throttle ); ctx->throttle = NULL; } + if ( ctx->access_control_list != NULL ) ctx->access_control_list = httplib_free( ctx->access_control_list ); + if ( ctx->access_log_file != NULL ) ctx->access_log_file = httplib_free( ctx->access_log_file ); + if ( ctx->cgi_environment != NULL ) ctx->cgi_environment = httplib_free( ctx->cgi_environment ); + if ( ctx->error_log_file != NULL ) ctx->error_log_file = httplib_free( ctx->error_log_file ); + if ( ctx->extra_mime_types != NULL ) ctx->extra_mime_types = httplib_free( ctx->extra_mime_types ); + if ( ctx->protect_uri != NULL ) ctx->protect_uri = httplib_free( ctx->protect_uri ); + if ( ctx->run_as_user != NULL ) ctx->run_as_user = httplib_free( ctx->run_as_user ); + if ( ctx->ssl_cipher_list != NULL ) ctx->ssl_cipher_list = httplib_free( ctx->ssl_cipher_list ); + if ( ctx->throttle != NULL ) ctx->throttle = httplib_free( ctx->throttle ); for (i = 0; i < NUM_OPTIONS; i++) { - if (ctx->cfg[i] != NULL) { - - httplib_free( ctx->cfg[i] ); - ctx->cfg[i] = NULL; - } + if ( ctx->cfg[i] != NULL ) ctx->cfg[i] = httplib_free( ctx->cfg[i] ); } /* @@ -112,8 +103,8 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { tmp_rh = ctx->handlers; ctx->handlers = tmp_rh->next; - httplib_free( tmp_rh->uri ); - if ( tmp_rh != NULL ) httplib_free( tmp_rh ); + tmp_rh->uri = httplib_free( tmp_rh->uri ); + if ( tmp_rh != NULL ) tmp_rh = httplib_free( tmp_rh ); } #ifndef NO_SSL @@ -134,11 +125,7 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { * Deallocate worker thread ID array */ - if ( ctx->workerthreadids != NULL ) { - - httplib_free( ctx->workerthreadids ); - ctx->workerthreadids = NULL; - } + if ( ctx->workerthreadids != NULL ) ctx->workerthreadids = httplib_free( ctx->workerthreadids ); /* * Deallocate the tls variable @@ -159,12 +146,12 @@ void XX_httplib_free_context( struct httplib_context *ctx ) { * deallocate system name string */ - httplib_free( ctx->systemName ); + if ( ctx->systemName != NULL ) ctx->systemName = httplib_free( ctx->systemName ); /* * Deallocate context itself */ - httplib_free( ctx ); + ctx = httplib_free( ctx ); } /* XX_httplib_free_context */ diff --git a/src/httplib_handle_cgi_request.c b/src/httplib_handle_cgi_request.c index 2abf6d1e..0083bbfa 100644 --- a/src/httplib_handle_cgi_request.c +++ b/src/httplib_handle_cgi_request.c @@ -306,8 +306,8 @@ void XX_httplib_handle_cgi_request( struct httplib_connection *conn, const char XX_httplib_send_file_data( conn, &fout, 0, INT64_MAX ); done: - httplib_free( blk.var ); - httplib_free( blk.buf ); + blk.var = httplib_free( blk.var ); + blk.buf = httplib_free( blk.buf ); if ( pid != (pid_t)-1 ) { @@ -326,7 +326,7 @@ done: if ( out != NULL ) fclose( out ); else if ( fdout[0] != -1 ) close( fdout[0] ); if ( err != NULL ) fclose( err ); else if ( fderr[0] != -1 ) close( fderr[0] ); - if ( buf != NULL ) httplib_free( buf ); + if ( buf != NULL ) buf = httplib_free( buf ); } /* XX_httplib_handle_cgi_request */ diff --git a/src/httplib_handle_directory_request.c b/src/httplib_handle_directory_request.c index e2084191..6afd6da4 100644 --- a/src/httplib_handle_directory_request.c +++ b/src/httplib_handle_directory_request.c @@ -95,10 +95,10 @@ void XX_httplib_handle_directory_request( struct httplib_connection *conn, const for (i=0; inum_bytes_sent += httplib_printf( conn, "%s", "" ); diff --git a/src/httplib_handle_form_request.c b/src/httplib_handle_form_request.c index 9d394a6c..fdfde548 100644 --- a/src/httplib_handle_form_request.c +++ b/src/httplib_handle_form_request.c @@ -110,9 +110,8 @@ static int url_encoded_field_get(const struct httplib_connection *conn, httplib_url_decode( key, (int)key_len, key_dec, (int)sizeof(key_dec), 1 ); value_dec_len = httplib_url_decode( value, (int)value_len, value_dec, (int)value_len + 1, 1 ); - - ret = fdh->field_get( key_dec, value_dec, (size_t)value_dec_len, fdh->user_data ); - httplib_free( value_dec ); + ret = fdh->field_get( key_dec, value_dec, (size_t)value_dec_len, fdh->user_data ); + value_dec = httplib_free( value_dec ); return ret; diff --git a/src/httplib_main.h b/src/httplib_main.h index 2af215f4..39bb5e42 100644 --- a/src/httplib_main.h +++ b/src/httplib_main.h @@ -398,7 +398,6 @@ enum { SSI_EXTENSIONS, GLOBAL_PASSWORDS_FILE, INDEX_FILES, - ACCESS_CONTROL_LIST, LISTENING_PORTS, DOCUMENT_ROOT, SSL_CERTIFICATE, @@ -587,6 +586,7 @@ struct httplib_context { #ifdef USE_TIMERS struct ttimers *timers; #endif + char * access_control_list; char * access_log_file; char * cgi_environment; char * error_log_file; diff --git a/src/httplib_malloc.c b/src/httplib_malloc.c index 203ef069..2461fa0a 100644 --- a/src/httplib_malloc.c +++ b/src/httplib_malloc.c @@ -110,23 +110,26 @@ LIBHTTP_API void *XX_httplib_calloc_ex( size_t count, size_t size, const char *f /* - * void XX_httplib_free_ex( void *memory, const char *file, unsigned file ); + * void *XX_httplib_free_ex( void *memory, const char *file, unsigned file ); * * The function XX_httplib_free_ex() is a hidden function which frees a * previously allocated memory object which was allocated with one of the * LibHTTP allocation functions. The function has the option to do memory * tracking and memory leak debugging through a callback function which can * be registered by the main application. + * + * The function returns a (void *)NULL pointer which can be used to reset + * the value of pointers whose contents has been destroyed. */ -LIBHTTP_API void XX_httplib_free_ex( void *memory, const char *file, unsigned line ) { +LIBHTTP_API void *XX_httplib_free_ex( void *memory, const char *file, unsigned line ) { size_t *data; if ( memory == NULL ) { if ( alloc_log_func != NULL ) alloc_log_func( file, line, "free", 0, httplib_memory_blocks_used, httplib_memory_bytes_used ); - return; + return NULL; } data = ((size_t *)memory) - 1; @@ -138,6 +141,8 @@ LIBHTTP_API void XX_httplib_free_ex( void *memory, const char *file, unsigned li free( data ); + return NULL; + } /* XX_httplib_free_ex */ diff --git a/src/httplib_opendir.c b/src/httplib_opendir.c index 3f4ed9ee..67f247d1 100644 --- a/src/httplib_opendir.c +++ b/src/httplib_opendir.c @@ -60,10 +60,7 @@ LIBHTTP_API DIR *httplib_opendir( const char *name ) { dir->handle = FindFirstFileW( wpath, &dir->info ); dir->result.d_name[0] = '\0'; } - else { - httplib_free( dir ); - dir = NULL; - } + else dir = httplib_free( dir ); } return dir; diff --git a/src/httplib_read_websocket.c b/src/httplib_read_websocket.c index b20ebd05..9892ffd8 100644 --- a/src/httplib_read_websocket.c +++ b/src/httplib_read_websocket.c @@ -251,7 +251,7 @@ void XX_httplib_read_websocket( struct httplib_connection *conn, httplib_websock exit_by_callback = 0; if ((ws_data_handler != NULL) && !ws_data_handler(conn, mop, data, data_len, callback_data)) exit_by_callback = 1; - if ( data != mem ) httplib_free( data ); + if ( data != mem ) data = httplib_free( data ); /* * Opcode == 8, connection close diff --git a/src/httplib_set_handler_type.c b/src/httplib_set_handler_type.c index f2d85021..337ab0fe 100644 --- a/src/httplib_set_handler_type.c +++ b/src/httplib_set_handler_type.c @@ -111,9 +111,10 @@ void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri, /* * remove existing handler */ - *lastref = tmp_rh->next; - httplib_free( tmp_rh->uri ); - httplib_free( tmp_rh ); + + *lastref = tmp_rh->next; + tmp_rh->uri = httplib_free( tmp_rh->uri ); + tmp_rh = httplib_free( tmp_rh ); } httplib_unlock_context(ctx); @@ -149,7 +150,7 @@ void XX_httplib_set_handler_type( struct httplib_context *ctx, const char *uri, if ( tmp_rh->uri == NULL ) { httplib_unlock_context( ctx ); - httplib_free( tmp_rh ); + tmp_rh = httplib_free( tmp_rh ); httplib_cry( ctx, NULL, "%s", "Cannot create new request handler struct, OOM" ); return; diff --git a/src/httplib_start.c b/src/httplib_start.c index af413f5d..73e8c15c 100644 --- a/src/httplib_start.c +++ b/src/httplib_start.c @@ -120,7 +120,7 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks httplib_atomic_dec( & XX_httplib_sTlsInit ); httplib_cry( ctx, NULL, "Cannot initialize thread local storage" ); - httplib_free( ctx ); + ctx = httplib_free( ctx ); return NULL; } @@ -248,7 +248,7 @@ struct httplib_context *httplib_start( const struct httplib_callbacks *callbacks * thread was not created */ - if ( wta != NULL ) { httplib_free( wta ); wta = NULL; } + if ( wta != NULL ) wta = httplib_free( wta ); if ( i > 0 ) httplib_cry( ctx, NULL, "Cannot start worker thread %i: error %ld", i + 1, (long)ERRNO ); @@ -284,6 +284,7 @@ static bool process_options( struct httplib_context *ctx, const struct httplib_o if ( ctx == NULL ) return false; + ctx->access_control_list = NULL; ctx->access_log_file = NULL; ctx->allow_sendfile_call = true; ctx->cgi_environment = NULL; @@ -309,6 +310,7 @@ static bool process_options( struct httplib_context *ctx, const struct httplib_o while ( options != NULL && options->name != NULL ) { + if ( check_str( ctx, options, "access_control_list", & ctx->access_control_list ) ) return true; if ( check_file( ctx, options, "access_log_file", & ctx->access_log_file ) ) return true; if ( check_bool( ctx, options, "allow_sendfile_call", & ctx->allow_sendfile_call ) ) return true; if ( check_str( ctx, options, "cgi_environment", & ctx->cgi_environment ) ) return true; @@ -342,7 +344,7 @@ static bool process_options( struct httplib_context *ctx, const struct httplib_o if ( ctx->cfg[idx] != NULL ) { httplib_cry( ctx, NULL, "warning: %s: duplicate option", options->name ); - httplib_free( ctx->cfg[idx] ); + ctx->cfg[idx] = httplib_free( ctx->cfg[idx] ); } ctx->cfg[idx] = httplib_strdup( options->value ); @@ -417,8 +419,7 @@ static bool check_file( struct httplib_context *ctx, const struct httplib_option if ( httplib_strcasecmp( option->name, name ) ) return false; - if ( *config != NULL ) httplib_free( *config ); - *config = NULL; + if ( *config != NULL ) *config = httplib_free( *config ); if ( option->value == NULL ) return false; @@ -453,8 +454,7 @@ static bool check_str( struct httplib_context *ctx, const struct httplib_option_ if ( httplib_strcasecmp( option->name, name ) ) return false; - if ( *config != NULL ) httplib_free( *config ); - *config = NULL; + if ( *config != NULL ) *config = httplib_free( *config ); if ( option->value == NULL ) return false; diff --git a/src/httplib_timer.c b/src/httplib_timer.c index 1cf78ed3..1e55cb97 100644 --- a/src/httplib_timer.c +++ b/src/httplib_timer.c @@ -198,7 +198,7 @@ static void timers_exit( struct httplib_context *ctx ) { if ( ctx->timers != NULL ) { httplib_pthread_mutex_destroy( & ctx->timers->mutex ); - httplib_free( ctx->timers ); + ctx->timers = httplib_free( ctx->timers ); } } /* timers_exit */ diff --git a/src/httplib_tls_dtor.c b/src/httplib_tls_dtor.c index 41521a69..d266993c 100644 --- a/src/httplib_tls_dtor.c +++ b/src/httplib_tls_dtor.c @@ -48,7 +48,7 @@ void XX_httplib_tls_dtor( void *key ) { if ( tls->is_master == 2 ) { tls->is_master = -3; /* Mark memory as dead */ - httplib_free( tls ); + tls = httplib_free( tls ); } } diff --git a/src/httplib_uninitialize_ssl.c b/src/httplib_uninitialize_ssl.c index 3801c31c..e8f7f14f 100644 --- a/src/httplib_uninitialize_ssl.c +++ b/src/httplib_uninitialize_ssl.c @@ -64,8 +64,7 @@ void XX_httplib_uninitialize_ssl( struct httplib_context *ctx ) { for (i=0; i 0 ) len = httplib_write( conn, buf, (size_t)len ); - if ( buf != mem && buf != NULL ) httplib_free( buf ); + if ( buf != mem && buf != NULL ) buf = httplib_free( buf ); return len; diff --git a/src/httplib_websocket_client_thread.c b/src/httplib_websocket_client_thread.c index 2fb0ca7a..8db756d6 100644 --- a/src/httplib_websocket_client_thread.c +++ b/src/httplib_websocket_client_thread.c @@ -56,7 +56,7 @@ LIBHTTP_THREAD XX_httplib_websocket_client_thread( void *data ) { if ( cdata->close_handler != NULL ) cdata->close_handler( cdata->conn, cdata->callback_data ); - httplib_free( cdata ); + cdata = httplib_free( cdata ); return LIBHTTP_THREAD_RETNULL; diff --git a/src/httplib_websocket_client_write.c b/src/httplib_websocket_client_write.c index 61efa2bb..353281a2 100644 --- a/src/httplib_websocket_client_write.c +++ b/src/httplib_websocket_client_write.c @@ -58,8 +58,8 @@ int httplib_websocket_client_write( struct httplib_connection *conn, int opcode, mask_data( data, dataLen, masking_key, masked_data ); - retval = XX_httplib_websocket_write_exec( conn, opcode, masked_data, dataLen, masking_key ); - httplib_free( masked_data ); + retval = XX_httplib_websocket_write_exec( conn, opcode, masked_data, dataLen, masking_key ); + masked_data = httplib_free( masked_data ); return retval; diff --git a/src/httplib_worker_thread.c b/src/httplib_worker_thread.c index 32bce71e..e66679a5 100644 --- a/src/httplib_worker_thread.c +++ b/src/httplib_worker_thread.c @@ -49,7 +49,7 @@ LIBHTTP_THREAD XX_httplib_worker_thread( void *thread_func_param ) { pwta = thread_func_param; worker_thread_run( pwta ); - httplib_free( thread_func_param ); + thread_func_param = httplib_free( thread_func_param ); } return LIBHTTP_THREAD_RETNULL; @@ -158,13 +158,11 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) { if ( conn->request_info.client_cert != NULL ) { - ptr.con = conn->request_info.client_cert->subject; httplib_free( ptr.var ); - ptr.con = conn->request_info.client_cert->issuer; httplib_free( ptr.var ); - ptr.con = conn->request_info.client_cert->serial; httplib_free( ptr.var ); - ptr.con = conn->request_info.client_cert->finger; httplib_free( ptr.var ); - httplib_free( conn->request_info.client_cert ); - - conn->request_info.client_cert = NULL; + ptr.con = conn->request_info.client_cert->subject; ptr.var = httplib_free( ptr.var ); + ptr.con = conn->request_info.client_cert->issuer; ptr.var = httplib_free( ptr.var ); + ptr.con = conn->request_info.client_cert->serial; ptr.var = httplib_free( ptr.var ); + ptr.con = conn->request_info.client_cert->finger; ptr.var = httplib_free( ptr.var ); + conn->request_info.client_cert = httplib_free( conn->request_info.client_cert ); } } #endif @@ -181,7 +179,7 @@ static void *worker_thread_run( struct worker_thread_args *thread_args ) { CloseHandle( tls.pthread_cond_helper_mutex ); #endif httplib_pthread_mutex_destroy( & conn->mutex ); - httplib_free( conn ); + conn = httplib_free( conn ); return NULL;