fix(ai): use atomic ai_provider_ref() in cmd_ai_switch
Some checks failed
CI Code / Linux (arch) (pull_request) Failing after 10m9s
CI Code / Code Coverage (pull_request) Failing after 14m6s
CI Code / Check spelling (pull_request) Failing after 14m27s
CI Code / Check coding style (pull_request) Failing after 14m44s
CI Code / Linux (ubuntu) (pull_request) Failing after 15m9s
CI Code / Linux (debian) (pull_request) Failing after 15m43s

src/command/cmd_funcs:11118 used a plain non-atomic ref_count++ on
ai_provider, which is a data race against concurrent
ai_provider_unref() calls using g_atomic_int_dec_and_test.

- Expose ai_provider_ref() in ai_client.h (was static)
- Replace non-atomic ref_count++ with ai_provider_ref() in cmd_ai_switch"
This commit is contained in:
2026-05-11 21:15:10 +00:00
parent 107f7778e2
commit b1dbe714e8
3 changed files with 9 additions and 2 deletions

View File

@@ -205,7 +205,7 @@ ai_provider_new(const gchar* name, const gchar* api_url, const gchar* org_id)
return provider;
}
static AIProvider*
AIProvider*
ai_provider_ref(AIProvider* provider)
{
if (provider) {

View File

@@ -78,6 +78,13 @@ AIProvider* ai_add_provider(const gchar* name, const gchar* api_url, const gchar
*/
gboolean ai_remove_provider(const gchar* name);
/**
* Increment the reference count of a provider.
* @param provider The provider to reference
* @return The same provider pointer
*/
AIProvider* ai_provider_ref(AIProvider* provider);
/**
* Decrement the reference count of a provider.
* @param provider The provider to unreference

View File

@@ -11115,7 +11115,7 @@ cmd_ai_switch(ProfWin* window, const char* const command, gchar** args)
aiwin->session->provider_name = g_strdup(provider_name);
ai_provider_unref(aiwin->session->provider);
aiwin->session->provider = new_provider;
aiwin->session->provider->ref_count++;
ai_provider_ref(aiwin->session->provider);
}
g_free(aiwin->session->model);
aiwin->session->model = g_strdup(model);