mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-17 23:26:20 +00:00
fix(ai): fix memory leaks in ai session handling
Add missing `ai_session_unref` calls to prevent memory leaks. - In `_ai_request_thread`, release session on error paths and after successful processing. - In `cmd_ai_start`, release reference after passing ownership to the AI window.
This commit is contained in:
@@ -1434,6 +1434,7 @@ _ai_request_thread(gpointer data)
|
||||
local_provider_name, local_provider_name);
|
||||
log_error("AI request failed for %s/%s: %s", local_provider_name, local_model, error_msg);
|
||||
_aiwin_display_error(user_data, error_msg);
|
||||
ai_session_unref(session);
|
||||
g_free(args);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1444,6 +1445,7 @@ _ai_request_thread(gpointer data)
|
||||
log_error("AI request failed for %s/%s: Failed to initialize curl",
|
||||
local_provider_name, local_model);
|
||||
_aiwin_display_error(user_data, "Failed to initialize curl.");
|
||||
ai_session_unref(session);
|
||||
g_free(args);
|
||||
return NULL;
|
||||
}
|
||||
@@ -1531,6 +1533,7 @@ _ai_request_thread(gpointer data)
|
||||
|
||||
ai_provider_unref(local_provider);
|
||||
|
||||
ai_session_unref(session);
|
||||
g_free(args);
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -10981,6 +10981,9 @@ cmd_ai_start(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
log_debug("[AI-CMD] wins_new_ai() returned successfully, window type: %d", ai_win->type);
|
||||
|
||||
// Release the reference held by cmd_ai_start, since the window now holds one
|
||||
ai_session_unref(session);
|
||||
|
||||
// Add welcome message to the AI window
|
||||
log_debug("[AI-CMD] Adding welcome messages...");
|
||||
win_println(ai_win, THEME_DEFAULT, "-", "AI Chat: %s/%s", provider_name, model);
|
||||
|
||||
Reference in New Issue
Block a user