From 3a721e1d96720505d4d6638e77d2c296d962519c Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Sun, 9 Aug 2020 10:26:19 +0300 Subject: [PATCH] Fixing leaked configuration objects. If there are no listen sockets, the router configuration usage counter remains 0 and never decreases. The only moment to release a configuration is right after a configuration update. --- src/nxt_router.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/nxt_router.c b/src/nxt_router.c index 8b3f3daf..758310a9 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1208,13 +1208,39 @@ nxt_router_conf_wait(nxt_task_t *task, void *obj, void *data) static void nxt_router_conf_ready(nxt_task_t *task, nxt_router_temp_conf_t *tmcf) { - nxt_debug(task, "temp conf count:%D", tmcf->count); + uint32_t count; + nxt_router_conf_t *rtcf; + nxt_thread_spinlock_t *lock; - if (--tmcf->count == 0) { - nxt_router_conf_send(task, tmcf, NXT_PORT_MSG_RPC_READY_LAST); + nxt_debug(task, "temp conf %p count: %D", tmcf, tmcf->count); - nxt_mp_destroy(tmcf->mem_pool); + if (--tmcf->count > 0) { + return; } + + nxt_router_conf_send(task, tmcf, NXT_PORT_MSG_RPC_READY_LAST); + + rtcf = tmcf->router_conf; + + lock = &rtcf->router->lock; + + nxt_thread_spin_lock(lock); + + count = rtcf->count; + + nxt_thread_spin_unlock(lock); + + nxt_debug(task, "rtcf %p: %D", rtcf, count); + + if (count == 0) { + nxt_http_routes_cleanup(task, rtcf->routes); + + nxt_router_access_log_release(task, lock, rtcf->access_log); + + nxt_mp_destroy(rtcf->mem_pool); + } + + nxt_mp_destroy(tmcf->mem_pool); }