Browse Source

check if context is initialized

Philipp Friedenberger 10 năm trước cách đây
mục cha
commit
2f7f94bbfc
1 tập tin đã thay đổi với 7 bổ sung0 xóa
  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);