Explorar o código

check if context is initialized

Philipp Friedenberger %!s(int64=10) %!d(string=hai) anos
pai
achega
2f7f94bbfc
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  1. 7 0
      src/CivetServer.cpp

+ 7 - 0
src/CivetServer.cpp

@@ -55,6 +55,10 @@ int CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
     assert(request_info != NULL);
     CivetServer *me = (CivetServer*) (request_info->user_data);
     assert(me != NULL);
+
+    // Happens when a request hits the server before the context is saved
+    if (me->context == NULL) return;
+
     mg_lock_context(me->context);
     me->connections[conn] = CivetConnection();
     mg_unlock_context(me->context);
@@ -107,6 +111,9 @@ void CivetServer::closeHandler(struct mg_connection *conn)
     CivetServer *me = (CivetServer*) (request_info->user_data);
     assert(me != NULL);
 
+    // Happens when a request hits the server before the context is saved
+    if (me->context == NULL) return;
+
     if (me->userCloseHandler) me->userCloseHandler(conn);
     mg_lock_context(me->context);
     me->connections.erase(conn);