Close leaked file handle in orgnode parser (#1284)

## Summary

`src/khoj/processor/content/org_mode/orgnode.py:57` opens a file with
`open(filename, "r")` but never closes it. The file handle leaks for the
lifetime of the returned `Orgnode` list.

## Fix

Replaced bare `open()` with a `with` statement to ensure the file is
closed after `makelist()` finishes reading.

```python
# Before
def makelist_with_filepath(filename):
    f = open(filename, "r")
    return makelist(f, filename)

# After
def makelist_with_filepath(filename):
    with open(filename, "r") as f:
        return makelist(f, filename)
```

This is safe because `makelist()` fully consumes the file during the
call (building the Orgnode list from file contents), so the file handle
is no longer needed after it returns.
This commit is contained in:
Tay 2026-03-25 05:33:20 -07:00 committed by GitHub
parent 530443a4f6
commit 0e169159f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,8 +54,8 @@ def normalize_filename(filename):
def makelist_with_filepath(filename):
f = open(filename, "r")
return makelist(f, filename)
with open(filename, "r") as f:
return makelist(f, filename)
def makelist(file, filename, start_line: int = 1, ancestry_lines: int = 0) -> List["Orgnode"]: