mirror of
https://github.com/khoj-ai/khoj
synced 2026-04-21 15:57:17 +00:00
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:
parent
530443a4f6
commit
0e169159f8
1 changed files with 2 additions and 2 deletions
|
|
@ -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"]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue