From 1fd406d47686cc6cde1ae808f0b72ac77c2dda7d Mon Sep 17 00:00:00 2001 From: Jacob Skillin Date: Fri, 19 Feb 2016 13:18:42 -0500 Subject: [PATCH 1/2] Only free conn if in client context. The worker_thread_run function will free the conn memory when it quits. Freeing it in mg_close_connection frees it too early, causing a crash in the worker_thread_run function as it reuses conn until the server quits and asks the thread to quit. --- src/civetweb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/civetweb.c b/src/civetweb.c index 42e57d2f..479b9b7e 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -10971,9 +10971,9 @@ mg_close_connection(struct mg_connection *conn) } mg_free(client_ctx->workerthreadids); mg_free(client_ctx); + mg_free(conn); } (void)pthread_mutex_destroy(&conn->mutex); - mg_free(conn); } From c793d57105bd9f12bbf8ac823cefead647abf3a8 Mon Sep 17 00:00:00 2001 From: Jacob Skillin Date: Fri, 19 Feb 2016 13:24:07 -0500 Subject: [PATCH 2/2] Free mutex prior to freeing conn The worker_thread_run will handle freeing the mutex in a server context --- src/civetweb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/civetweb.c b/src/civetweb.c index 479b9b7e..98369006 100644 --- a/src/civetweb.c +++ b/src/civetweb.c @@ -10971,9 +10971,9 @@ mg_close_connection(struct mg_connection *conn) } mg_free(client_ctx->workerthreadids); mg_free(client_ctx); + (void)pthread_mutex_destroy(&conn->mutex); mg_free(conn); } - (void)pthread_mutex_destroy(&conn->mutex); }