summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2025-08-12 22:48:32 +0100
committerAndrew Clayton <a.clayton@nginx.com>2025-08-20 13:58:32 +0100
commit1701935ea4a55f3ce4b5da5db866fc1b11558e0c (patch)
tree635985dc76461c7a0e2b5f5a48949de9e3dc71bd
parent5e97e44df4bf80ee6914c3fe42c57d6c674c3279 (diff)
downloadunit-1701935ea4a55f3ce4b5da5db866fc1b11558e0c.tar.gz
unit-1701935ea4a55f3ce4b5da5db866fc1b11558e0c.tar.bz2
Don't leak file descriptor in nxt_main_port_access_log_handler()
After opening a file and setting file.fd we _may_ call nxt_port_socket_write(). If so then the file is eventually closed via something like nxt_port_socket_write() nxt_port_socket_write2() nxt_port_write_handler() nxt_port_msg_close_fd() nxt_port_close_fds() Alternatively we may just return from the function and never close(2) file.fd. In which case we should call nxt_file_close(). This was reported by coverity. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r--src/nxt_main_process.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index e942c1a8..25798ea0 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -1730,5 +1730,8 @@ nxt_main_port_access_log_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
if (nxt_fast_path(port != NULL)) {
(void) nxt_port_socket_write(task, port, type, file.fd,
msg->port_msg.stream, 0, NULL);
+
+ } else {
+ nxt_file_close(task, &file);
}
}