From 2b53c7bbbd518131b46867343caaad18534ebd8f Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 5 Aug 2020 14:55:34 +0300 Subject: Fixed nxt_conn_accept_alloc() behavior in low memory conditions. Earlier, if nxt_mp_create() failed to allocate memory while accepting a new connection, the resulting NULL was subsequently passed to nxt_mp_destroy(), crashing the process. More, if nxt_mp_create() was successful but nxt_sockaddr_cache_alloc() failed, the connection object wasn't destroyed properly, leaving the connection counter in an inconsistent state. Repeated, this condition lowered the connection capacity of the process and could eventually prevent it from accepting connections altogether. --- src/nxt_conn_accept.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nxt_conn_accept.c') diff --git a/src/nxt_conn_accept.c b/src/nxt_conn_accept.c index 6a89840c..77c44c58 100644 --- a/src/nxt_conn_accept.c +++ b/src/nxt_conn_accept.c @@ -98,7 +98,9 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev) if (nxt_fast_path(mp != NULL)) { c = nxt_conn_create(mp, lev->socket.task); if (nxt_slow_path(c == NULL)) { - goto fail; + nxt_mp_destroy(mp); + + return NULL; } c->socket.read_work_queue = lev->socket.read_work_queue; @@ -109,11 +111,9 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev) lev->next = c; return c; } - } - fail: - - nxt_mp_destroy(mp); + nxt_conn_free(task, c); + } } return NULL; -- cgit