🧱 Chunk is a download manager for slow and unstable servers

File handle leak when progress-file initialization fails #9

Open cuducos.me
Open opened by cuducos.me

Problem

prepareAndStartDownload calls os.OpenFile for the output file (downloader.go:335), then newProgress (downloader.go:342). The deferred close of the file is only registered after that (downloader.go:349-357), so if newProgress fails, the function returns early (downloader.go:343-346) and the output file stays open until the process exits.

Impact

Resource leak; on long-running or repeated failure paths this can exhaust file descriptors.

Suggested fix

Register the f.Close() defer immediately after os.OpenFile.

Sign up or Sign in to add to the discussion.