This is a patch to fix all the 'free-without-setting to NULL' problems. Some of these are addressed in later version of mongoose. diff --git a/mongoose.c b/mongoose.c index b92dec7..60d35ff 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1173,6 +1173,7 @@ static int closedir(DIR *dir) { result = FindClose(dir->handle) ? 0 : -1; free(dir); + dir=NULL; } else { result = -1; SetLastError(ERROR_BAD_ARGUMENTS); @@ -4279,6 +4280,7 @@ static void close_all_listening_sockets(struct mg_context *ctx) { closesocket(ctx->listening_sockets[i].sock); } free(ctx->listening_sockets); + ctx->listening_sockets = NULL; } // Valid listening port specification is: [ip_address:]port[s] @@ -4653,6 +4655,7 @@ static void close_connection(struct mg_connection *conn) { // Must be done AFTER socket is closed if (conn->ssl != NULL) { SSL_free(conn->ssl); + conn->ssl = NULL; } #endif } @@ -4661,10 +4664,12 @@ void mg_close_connection(struct mg_connection *conn) { #ifndef NO_SSL if (conn->client_ssl_ctx != NULL) { SSL_CTX_free((SSL_CTX *) conn->client_ssl_ctx); + conn->client_ssl_ctx = NULL; } #endif close_connection(conn); free(conn); + conn = NULL; } struct mg_connection *mg_connect(const char *host, int port, int use_ssl, @@ -4815,6 +4820,7 @@ static void process_new_connection(struct mg_connection *conn) { } if (ri->remote_user != NULL) { free((void *) ri->remote_user); + ri->remote_user = NULL; } // NOTE(lsm): order is important here. should_keep_alive() call @@ -4907,6 +4913,7 @@ static void *worker_thread(void *thread_func_param) { close_connection(conn); } free(conn); + conn = NULL; } // Signal master that we're done with connection and exiting @@ -5061,6 +5068,7 @@ static void free_context(struct mg_context *ctx) { // Deallocate SSL context if (ctx->ssl_ctx != NULL) { SSL_CTX_free(ctx->ssl_ctx); + ctx->ssl_ctx = NULL; } if (ssl_mutexes != NULL) { free(ssl_mutexes); @@ -5070,6 +5078,7 @@ static void free_context(struct mg_context *ctx) { // Deallocate context itself free(ctx); + ctx = NULL; } void mg_stop(struct mg_context *ctx) {