From c941a1a39a3df59e6c66dc394414766d89067a4b Mon Sep 17 00:00:00 2001 From: Sergey Lyubka <valenok@gmail.com> Date: Fri, 22 Aug 2014 16:26:30 +0100 Subject: [PATCH] Proper struct mg_connection cleanup in close_local_endpoint() --- mongoose.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mongoose.c b/mongoose.c index 61ef71da9..80a451c52 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4640,7 +4640,12 @@ static void close_local_endpoint(struct connection *conn) { conn->ns_conn->flags &= ~(NSF_FINISHED_SENDING_DATA | NSF_BUFFER_BUT_DONT_SEND | NSF_CLOSE_IMMEDIATELY | MG_HEADERS_SENT | MG_LONG_RUNNING); - memset(c, 0, sizeof(*c)); + + // Do not memset() the whole structure, as some of the fields + // (IP addresses & ports, server_param) must survive. Nullify the rest. + c->request_method = c->uri = c->http_version = c->query_string = NULL; + c->num_headers = c->status_code = c->is_websocket = c->content_len = 0; + c->connection_param = c->callback_param = NULL; if (keep_alive) { on_recv_data(conn); // Can call us recursively if pipelining is used -- GitLab