Skip to content

Bug: File Descriptor Leaks in Generator #38

@Jaydeep869

Description

@Jaydeep869

Description

runSyft and runTrivy in pkg/generator/generator.go create temporary files but do not reliably close them in all paths. This can leak file descriptors and, on some platforms, keep file locks active.

Steps to Reproduce

  1. Run SBOM generation repeatedly in a loop (especially on macOS/Windows).
  2. Observe open file descriptors or temp file lock behavior while syft/trivy subprocesses run.
  3. Notice occasional write/open failures or steadily increasing descriptors.

Expected Behavior

Temporary files are always closed correctly, and subprocesses can write to them without lock conflicts.

Actual Behavior

File descriptors may remain open longer than needed, and subprocesses may fail when exclusive file access is required.

Environment

  • sbomit version: current main branch
  • OS: Linux/macOS/Windows (lock issues are more visible on macOS/Windows)

Additional Context

  • Area: pkg/generator/generator.go
  • Suggested fix:
    • Add defer tmpFile.Close() right after successful temp file creation.
    • If subprocess needs exclusive write access, call tmpFile.Close() before launching the subprocess and only pass the path.

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