Skip to content

fix: close leaked file handle in orgnode parser#1284

Open
buley wants to merge 1 commit intokhoj-ai:masterfrom
buley:fix/close-leaked-file-handle-orgnode
Open

fix: close leaked file handle in orgnode parser#1284
buley wants to merge 1 commit intokhoj-ai:masterfrom
buley:fix/close-leaked-file-handle-orgnode

Conversation

@buley
Copy link

@buley buley commented Mar 20, 2026

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.

# 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.

open() was called without a context manager, so the file handle leaked
for the lifetime of the returned Orgnode list. Replaced with 'with'
statement to ensure the file is closed after makelist() reads it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant