From 09a604d47bfb076ff1711519cf442c68bf387d78 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 14 Jan 2026 19:39:08 -0300 Subject: [PATCH] fix: Use context manager for file reading in load_user Ensures proper resource cleanup by using 'with' statement instead of bare open() call when reading user profile files. --- modules/chat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/chat.py b/modules/chat.py index 91576785..91b75239 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -1683,7 +1683,9 @@ def load_user(user_name, name1, user_bio): logger.error(f"Could not find the user \"{user_name}\" inside user_data/users. No user has been loaded.") raise ValueError - file_contents = open(filepath, 'r', encoding='utf-8').read() + with open(filepath, 'r', encoding='utf-8') as f: + file_contents = f.read() + extension = filepath.suffix[1:] # Remove the leading dot data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents)