BBS:      TELESC.NET.BR
Assunto:  src/sbbs3/ftpsrvr.cpp
De:       Rob Swindell (on Windows 11)
Data:     Wed, 20 May 2026 16:55:04 -0700
-----------------------------------------------------------
https://gitlab.synchro.net/main/sbbs/-/commit/3f0508da6bce06fb59f76358
Modified Files:
	src/sbbs3/ftpsrvr.cpp
Log Message:
ftpsrvr: fix file-descriptor leaks in directory/index handlers

Two distinct leaks of per-command temp-file descriptors, both surfacing
as "ERROR 24 (Too many open files)" once the process exhausts its
descriptor table -- after which every temp-file open (LIST/MLSD .lst,
index .ndx, QWK packets, and even unrelated subsystems sharing the
process) fails in a storm.

1) MDTM  (getdate) opened a temp .ndx file via ftp_tmpfname()
   but never closed it: the lone fclose(fp) lives only in the !getdate
   (download) branch. Every MDTM on the dynamically-generated index file
   (startup->index_file_name, e.g. 00index) leaked one descriptor and
   orphaned an sbbstemp/SBBS_FTP.*.ndx file. FTP clients and crawlers
   MDTM each listed entry, so these accumulated steadily.
   Fix: don't open the temp file for a getdate/MDTM request at all (it is
   only needed to generate listing content); move the fopen into the
   !getdate branch.
   Introduced in 63e5e08f1c (2007-02-11), which made the index fopen
   unconditional and added early-outs for SIZE (continue) and MDTM
   (fall-through) that both bypassed the fclose. ff9ae78f44 (2007-11-28)
   fixed the SIZE half by moving its check above the fopen, but left the
   MDTM path leaking -- for ~18 years.

2) The MLSD, LIST and index-generation handlers "continue" out of the
   command loop on smb_open_dir() failure without closing the already-
   opened temp fp (and, for LIST/MLSD, without servicing the already-
   announced data connection). Triggers whenever a directory's .shd is
   locked or contended.
   Fix: close fp on the failure path; for LIST/MLSD also run the normal
   filexfer() cleanup so the data connection is serviced and the temp
   file removed.
   Introduced in 925e3b0a2 (2021-04-04), which migrated FTP directory
   listings to smb_open_dir()/loadfiles().

Co-Authored-By: Claude Opus 4.7 (1M context) 
n
---
  mSynchronetn  hgVertrauen n hHome of Synchronet n gh[vert/cvs/bbs].synchro.net

-----------------------------------------------------------
[Voltar]