diff --git a/mongoose.c b/mongoose.c index 31ef2ee8..a0daeebb 100644 --- a/mongoose.c +++ b/mongoose.c @@ -584,7 +584,7 @@ static void cry(struct mg_connection *conn, const char *fmt, ...) { // same way string option can. conn->log_message = buf; if (call_user(conn, MG_EVENT_LOG) == NULL) { - fp = conn->ctx->config[ERROR_LOG_FILE] == NULL ? NULL : + fp = conn->ctx == NULL || conn->ctx->config[ERROR_LOG_FILE] == NULL ? NULL : mg_fopen(conn->ctx->config[ERROR_LOG_FILE], "a+"); if (fp != NULL) {