diff --git a/mongoose.c b/mongoose.c index 86326a58..ed977a7f 100644 --- a/mongoose.c +++ b/mongoose.c @@ -399,9 +399,9 @@ void mg_error(struct mg_connection *c, const char *fmt, ...) { mg_vasprintf(&buf, sizeof(mem), fmt, ap); va_end(ap); LOG(LL_ERROR, ("%lu %s", c->id, buf)); - mg_call(c, MG_EV_ERROR, buf); + c->is_closing = 1; // Set is_closing before sending MG_EV_CALL + mg_call(c, MG_EV_ERROR, buf); // Let user handler to override it if (buf != mem) free(buf); - c->is_closing = 1; } #ifdef MG_ENABLE_LINES diff --git a/src/event.c b/src/event.c index f7d0036f..83fd23ea 100644 --- a/src/event.c +++ b/src/event.c @@ -18,7 +18,7 @@ void mg_error(struct mg_connection *c, const char *fmt, ...) { mg_vasprintf(&buf, sizeof(mem), fmt, ap); va_end(ap); LOG(LL_ERROR, ("%lu %s", c->id, buf)); - mg_call(c, MG_EV_ERROR, buf); + c->is_closing = 1; // Set is_closing before sending MG_EV_CALL + mg_call(c, MG_EV_ERROR, buf); // Let user handler to override it if (buf != mem) free(buf); - c->is_closing = 1; }