Skip to content

Don't leak file descriptor in nxt_main_port_access_log_handler() #1635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ac000
Copy link
Member

@ac000 ac000 commented Aug 12, 2025

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 <[email protected]>

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 <[email protected]>
@ac000 ac000 marked this pull request as ready for review August 12, 2025 22:15
@ac000 ac000 requested a review from hongzhidao August 12, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant