Skip to content

Bug: scheduler process cleanup leaks resources #427

Description

@pbalduino

Summary

The scheduler reap path does not appear to use the full process resource cleanup path. scheduler_cleanup_process frees some process-owned data, but can skip file descriptor cleanup and user VM region release.

That can leak file references, VM regions, and physical pages after terminated tasks are reaped.

Current Notes

Tracked locally in scheduler_issues.md as "Process Teardown Leaks Resources".

Relevant code:

  • src/kernel/proc/proc.c: scheduler_cleanup_process
  • src/kernel/proc/proc.c: proc_free_resources
  • src/kernel/proc/proc.c: proc_file_table_cleanup
  • src/kernel/proc/proc.c: proc_release_user_memory

Expected Behavior

A terminated process should release all owned resources exactly once when reaped, including stacks, file descriptors, VM regions, address-space mappings, and any process table entries.

Proposed Fix

Reuse proc_free_resources from scheduler_cleanup_process, or refactor teardown into a single helper with explicit ownership stages so scheduler reap, exec failure, and process exit paths cannot drift apart.

The fix should preserve zombie/wait semantics: resources that must remain visible to the parent should stay until wait, while heavyweight runtime resources should be released promptly and consistently.

Dependencies

Blocks

Related Issues

Validation

  • Add or update tests for process exit/reap resource cleanup where practical.
  • Stress repeated fork/exec/exit/wait cycles and inspect memory/file reference behavior.
  • Boot smoke test after userland process churn.
  • Confirm make test still passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingkernelKernel-level implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions