InterLinked1 / lbbs

Lightweight BBS For Linux - Bulletin Board System server software
GNU General Public License v2.0
35 stars 4 forks source link

pty.c/mod_sysop: File descriptor leak on shutdown #20

Open InterLinked1 opened 9 months ago

InterLinked1 commented 9 months ago

If a remote console is active during shutdown, a file descriptor leak (sometimes?) occurs of the PTY master, as shown here:

BBS has exited
==24657==
==24657== FILE DESCRIPTORS: 7 open (3 std) at exit.
==24657== Open file descriptor 19: /dev/ptmx
==24657==    at 0x5161E60: open (open64.c:41)
==24657==    by 0x13567D: posix_openpty (pty.c:61)
==24657==    by 0x136C1F: bbs_openpty (pty.c:94)
==24657==    by 0x136C1F: bbs_spawn_pty_master (pty.c:212)
==24657==    by 0x8417815: remote_sysop_listener (mod_sysop.c:508)
==24657==    by 0x145596: thread_run (thread.c:357)
==24657==    by 0x50F3043: start_thread (pthread_create.c:442)
==24657==    by 0x517285F: clone (clone.S:100)
==24657==
==24657== Open file descriptor 18: /dev/ptmx
==24657==    at 0x5161E60: open (open64.c:41)
==24657==    by 0x13567D: posix_openpty (pty.c:61)
==24657==    by 0x136C1F: bbs_openpty (pty.c:94)
==24657==    by 0x136C1F: bbs_spawn_pty_master (pty.c:212)
==24657==    by 0x8417815: remote_sysop_listener (mod_sysop.c:508)
==24657==    by 0x145596: thread_run (thread.c:357)
==24657==    by 0x50F3043: start_thread (pthread_create.c:442)
==24657==    by 0x517285F: clone (clone.S:100)
==24657==
==24657== Open file descriptor 16: /dev/ptmx
==24657==    at 0x5161E60: open (open64.c:41)
==24657==    by 0x13567D: posix_openpty (pty.c:61)
==24657==    by 0x136C1F: bbs_openpty (pty.c:94)
==24657==    by 0x136C1F: bbs_spawn_pty_master (pty.c:212)
==24657==    by 0x8417815: remote_sysop_listener (mod_sysop.c:508)
==24657==    by 0x145596: thread_run (thread.c:357)
==24657==    by 0x50F3043: start_thread (pthread_create.c:442)
==24657==    by 0x517285F: clone (clone.S:100)
==24657==
==24657== Open file descriptor 17: /dev/ptmx
==24657==    at 0x5161E60: open (open64.c:41)
==24657==    by 0x13567D: posix_openpty (pty.c:61)
==24657==    by 0x136C1F: bbs_openpty (pty.c:94)
==24657==    by 0x136C1F: bbs_spawn_pty_master (pty.c:212)
==24657==    by 0x8417815: remote_sysop_listener (mod_sysop.c:508)
==24657==    by 0x145596: thread_run (thread.c:357)
==24657==    by 0x50F3043: start_thread (pthread_create.c:442)
==24657==    by 0x517285F: clone (clone.S:100)
==24657==
==24657==
==24657== HEAP SUMMARY:
==24657==     in use at exit: 82,913 bytes in 764 blocks
==24657==   total heap usage: 14,851 allocs, 14,087 frees, 1,977,640 bytes allocated
==24657==

This is reflected in the (recently added) FD dump at shutdown, where /dev/ptmx is still open:

   16 => /dev/ptmx
Open files: 2 (7) / 1024
[2023-10-06 07:02:04.851]  === Finalizing shutdown