Skip to content

Commit 9469601

Browse files
committed
fix(chat): avoid memory leaks and unnecessary re-initialization in llm_chat_check_context
Adds a check to return early if the chat struct is already initialized, preventing memory leaks and unnecessary re-initialization and ensuring correct chat context handling.
1 parent 7e3b8c1 commit 9469601

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/sqlite-ai.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,9 @@ static bool llm_chat_check_context (ai_context *ai) {
14901490
llama_sampler_chain_add(ai->sampler, llama_sampler_init_dist((uint32_t)LLAMA_DEFAULT_SEED));
14911491
}
14921492

1493+
// initialize the chat struct if already created
1494+
if (ai->chat.uuid[0] != '\0') return true;
1495+
14931496
// create history structs
14941497
ai_uuid_v7_string(ai->chat.uuid, true);
14951498

0 commit comments

Comments
 (0)