Browse Source

Fixed potential dead-lock in connection_close()

This was posted by Morgan McGuire.
Thomas Davis 11 years ago
parent
commit
55c27d4751
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/civetweb.c

+ 2 - 2
src/civetweb.c

@@ -5326,12 +5326,12 @@ static void close_socket_gracefully(struct mg_connection *conn)
 
 
 static void close_connection(struct mg_connection *conn)
 static void close_connection(struct mg_connection *conn)
 {
 {
-    mg_lock(conn);
-
     // call the connection_close callback if assigned
     // call the connection_close callback if assigned
     if (conn->ctx->callbacks.connection_close != NULL)
     if (conn->ctx->callbacks.connection_close != NULL)
         conn->ctx->callbacks.connection_close(conn);
         conn->ctx->callbacks.connection_close(conn);
 
 
+    mg_lock(conn);
+
     conn->must_close = 1;
     conn->must_close = 1;
 
 
 #ifndef NO_SSL
 #ifndef NO_SSL