Skip to content

file descriptor leak in zeronet.py #240

@baronikatsu

Description

@baronikatsu

Step 1: Please describe your environment

  • ZeroNet version: 0.9.0 (latest)
  • Operating system: debian 12
  • Web browser: firefox
  • Tor status: disabled
  • Opened port: yes
  • Special configuration: no

Step 2: Describe the problem:

error_log_path = config.log_dir / "error.log"
traceback.print_exc(file=open(error_log_path, "w")) # File is never closed!

Fix: use with statement to make sure file is closed

error_log_path = config.log_dir / "error.log"
with open(error_log_path, "w") as f:
traceback.print_exc(file=f)

Steps to reproduce:

check zeronet.py

Observed:

This is a serious issue because:
The file is opened but never closed
This happens in an error handling path, so it could occur frequently
Each time it happens, it leaks a file descriptor
On systems with a low file descriptor limit, this could eventually cause the program to fail

Note:

This issue was also submitted to zeronet-conservancy, here:
zeronet-conservancy#305
And was committed here:
zeronet-conservancy@0188fde

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions