mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-25 20:28:27 +00:00
Fix #1331 - add comment about order of operations in conn_close()
This commit is contained in:
1 parent
c2c6ff11ed
commit
47ce072af7
3 files changed
+14
-10
No files matched your search
+7
-5
@@ -1344,6 +1344,7 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
status, mg_http_status_code_str(status), (int) mime.len, mime.ptr,
|
status, mg_http_status_code_str(status), (int) mime.len, mime.ptr,
|
||||||
etag, cl, range, opts->extra_headers ? opts->extra_headers : "");
|
etag, cl, range, opts->extra_headers ? opts->extra_headers : "");
|
||||||
if (mg_vcasecmp(&hm->method, "HEAD") == 0) {
|
if (mg_vcasecmp(&hm->method, "HEAD") == 0) {
|
||||||
|
c->is_draining = 1;
|
||||||
fs->close(fd);
|
fs->close(fd);
|
||||||
} else {
|
} else {
|
||||||
c->pfn = static_cb;
|
c->pfn = static_cb;
|
||||||
@@ -3091,23 +3092,24 @@ static void write_conn(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void close_conn(struct mg_connection *c) {
|
static void close_conn(struct mg_connection *c) {
|
||||||
// Unlink this connection from the list
|
mg_resolve_cancel(c); // Close any pending DNS query
|
||||||
mg_resolve_cancel(c);
|
|
||||||
LIST_DELETE(struct mg_connection, &c->mgr->conns, c);
|
LIST_DELETE(struct mg_connection, &c->mgr->conns, c);
|
||||||
if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL;
|
if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL;
|
||||||
if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL;
|
if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL;
|
||||||
|
// Order of operations is important. `MG_EV_CLOSE` event must be fired
|
||||||
|
// before we deallocate received data, see #1331
|
||||||
mg_call(c, MG_EV_CLOSE, NULL);
|
mg_call(c, MG_EV_CLOSE, NULL);
|
||||||
// while (c->callbacks != NULL) mg_fn_del(c, c->callbacks->fn);
|
|
||||||
LOG(LL_DEBUG, ("%lu closed", c->id));
|
LOG(LL_DEBUG, ("%lu closed", c->id));
|
||||||
if (FD(c) != INVALID_SOCKET) {
|
if (FD(c) != INVALID_SOCKET) {
|
||||||
closesocket(FD(c));
|
closesocket(FD(c));
|
||||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||||
FreeRTOS_FD_CLR(c->fd, c->mgr->ss, eSELECT_ALL);
|
FreeRTOS_FD_CLR(c->fd, c->mgr->ss, eSELECT_ALL);
|
||||||
#endif
|
#endif
|
||||||
|
c->fd = S2PTR(INVALID_SOCKET);
|
||||||
}
|
}
|
||||||
mg_tls_free(c);
|
mg_tls_free(c);
|
||||||
free(c->recv.buf);
|
mg_iobuf_free(&c->recv);
|
||||||
free(c->send.buf);
|
mg_iobuf_free(&c->send);
|
||||||
memset(c, 0, sizeof(*c));
|
memset(c, 0, sizeof(*c));
|
||||||
free(c);
|
free(c);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -573,6 +573,7 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
status, mg_http_status_code_str(status), (int) mime.len, mime.ptr,
|
status, mg_http_status_code_str(status), (int) mime.len, mime.ptr,
|
||||||
etag, cl, range, opts->extra_headers ? opts->extra_headers : "");
|
etag, cl, range, opts->extra_headers ? opts->extra_headers : "");
|
||||||
if (mg_vcasecmp(&hm->method, "HEAD") == 0) {
|
if (mg_vcasecmp(&hm->method, "HEAD") == 0) {
|
||||||
|
c->is_draining = 1;
|
||||||
fs->close(fd);
|
fs->close(fd);
|
||||||
} else {
|
} else {
|
||||||
c->pfn = static_cb;
|
c->pfn = static_cb;
|
||||||
|
|||||||
+6
-5
@@ -265,23 +265,24 @@ static void write_conn(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void close_conn(struct mg_connection *c) {
|
static void close_conn(struct mg_connection *c) {
|
||||||
// Unlink this connection from the list
|
mg_resolve_cancel(c); // Close any pending DNS query
|
||||||
mg_resolve_cancel(c);
|
|
||||||
LIST_DELETE(struct mg_connection, &c->mgr->conns, c);
|
LIST_DELETE(struct mg_connection, &c->mgr->conns, c);
|
||||||
if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL;
|
if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL;
|
||||||
if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL;
|
if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL;
|
||||||
|
// Order of operations is important. `MG_EV_CLOSE` event must be fired
|
||||||
|
// before we deallocate received data, see #1331
|
||||||
mg_call(c, MG_EV_CLOSE, NULL);
|
mg_call(c, MG_EV_CLOSE, NULL);
|
||||||
// while (c->callbacks != NULL) mg_fn_del(c, c->callbacks->fn);
|
|
||||||
LOG(LL_DEBUG, ("%lu closed", c->id));
|
LOG(LL_DEBUG, ("%lu closed", c->id));
|
||||||
if (FD(c) != INVALID_SOCKET) {
|
if (FD(c) != INVALID_SOCKET) {
|
||||||
closesocket(FD(c));
|
closesocket(FD(c));
|
||||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||||
FreeRTOS_FD_CLR(c->fd, c->mgr->ss, eSELECT_ALL);
|
FreeRTOS_FD_CLR(c->fd, c->mgr->ss, eSELECT_ALL);
|
||||||
#endif
|
#endif
|
||||||
|
c->fd = S2PTR(INVALID_SOCKET);
|
||||||
}
|
}
|
||||||
mg_tls_free(c);
|
mg_tls_free(c);
|
||||||
free(c->recv.buf);
|
mg_iobuf_free(&c->recv);
|
||||||
free(c->send.buf);
|
mg_iobuf_free(&c->send);
|
||||||
memset(c, 0, sizeof(*c));
|
memset(c, 0, sizeof(*c));
|
||||||
free(c);
|
free(c);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user