fix(ai): fix memory leaks in ai session handling
All checks were successful
CI Code / Check spelling (pull_request) Successful in 19s
CI Code / Check coding style (pull_request) Successful in 38s
CI Code / Code Coverage (pull_request) Successful in 2m55s
CI Code / Linux (debian) (pull_request) Successful in 4m39s
CI Code / Linux (ubuntu) (pull_request) Successful in 4m51s
CI Code / Linux (arch) (pull_request) Successful in 5m34s

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:
2026-05-15 11:58:25 +00:00
parent 7469f31c78
commit f9e0ba9630
2 changed files with 6 additions and 0 deletions

View File

@@ -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;

View File

@@ -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);