summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2020-04-15 15:10:14 +0300
committerIgor Sysoev <igor@sysoev.ru>2020-04-15 15:10:14 +0300
commitee62736a11acc4b699102a1260c6a8c5f57c1fef (patch)
treeae0791e8845a4013507130a1d1d781581a717692
parent04143c8c7ee59d24aa1d6df0377e7900e96e3f72 (diff)
downloadunit-ee62736a11acc4b699102a1260c6a8c5f57c1fef.tar.gz
unit-ee62736a11acc4b699102a1260c6a8c5f57c1fef.tar.bz2
Fixed memory leak occurring upon failure to accept a connection.
Diffstat (limited to '')
-rw-r--r--src/nxt_conn.h2
-rw-r--r--src/nxt_conn_accept.c21
2 files changed, 11 insertions, 12 deletions
diff --git a/src/nxt_conn.h b/src/nxt_conn.h
index 2c1d49a0..a443601f 100644
--- a/src/nxt_conn.h
+++ b/src/nxt_conn.h
@@ -106,7 +106,7 @@ typedef struct {
nxt_work_handler_t accept;
nxt_listen_socket_t *listen;
- nxt_conn_t *next; /* STUB */
+ nxt_conn_t *next;
nxt_work_queue_t *work_queue;
nxt_timer_t timer;
diff --git a/src/nxt_conn_accept.c b/src/nxt_conn_accept.c
index d4c3942c..6a89840c 100644
--- a/src/nxt_conn_accept.c
+++ b/src/nxt_conn_accept.c
@@ -101,12 +101,12 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev)
goto fail;
}
- lev->next = c;
c->socket.read_work_queue = lev->socket.read_work_queue;
c->socket.write_ready = 1;
c->remote = nxt_sockaddr_cache_alloc(engine, lev->listen);
if (nxt_fast_path(c->remote != NULL)) {
+ lev->next = c;
return c;
}
}
@@ -199,6 +199,7 @@ nxt_conn_accept(nxt_task_t *task, nxt_listen_event_t *lev, nxt_conn_t *c)
c->listen = lev;
lev->count++;
+ lev->next = NULL;
c->socket.data = NULL;
c->read_work_queue = lev->work_queue;
@@ -230,12 +231,14 @@ nxt_conn_accept_next(nxt_task_t *task, nxt_listen_event_t *lev)
{
nxt_conn_t *c;
- lev->next = NULL;
+ c = lev->next;
- c = nxt_conn_accept_alloc(task, lev);
+ if (c == NULL) {
+ c = nxt_conn_accept_alloc(task, lev);
- if (nxt_slow_path(c == NULL)) {
- nxt_conn_accept_close_idle(task, lev);
+ if (nxt_slow_path(c == NULL)) {
+ nxt_conn_accept_close_idle(task, lev);
+ }
}
return c;
@@ -355,14 +358,10 @@ nxt_conn_listen_timer_handler(nxt_task_t *task, void *obj, void *data)
timer = obj;
lev = nxt_timer_data(timer, nxt_listen_event_t, timer);
- c = lev->next;
+ c = nxt_conn_accept_next(task, lev);
if (c == NULL) {
- c = nxt_conn_accept_next(task, lev);
-
- if (c == NULL) {
- return;
- }
+ return;
}
nxt_fd_event_enable_accept(task->thread->engine, &lev->socket);