mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 13:46:21 +00:00
fix(ai): use atomic ai_provider_ref() in cmd_ai_switch
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:
@@ -205,7 +205,7 @@ ai_provider_new(const gchar* name, const gchar* api_url, const gchar* org_id)
|
|||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AIProvider*
|
AIProvider*
|
||||||
ai_provider_ref(AIProvider* provider)
|
ai_provider_ref(AIProvider* provider)
|
||||||
{
|
{
|
||||||
if (provider) {
|
if (provider) {
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ AIProvider* ai_add_provider(const gchar* name, const gchar* api_url, const gchar
|
|||||||
*/
|
*/
|
||||||
gboolean ai_remove_provider(const gchar* name);
|
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.
|
* Decrement the reference count of a provider.
|
||||||
* @param provider The provider to unreference
|
* @param provider The provider to unreference
|
||||||
|
|||||||
@@ -11115,7 +11115,7 @@ cmd_ai_switch(ProfWin* window, const char* const command, gchar** args)
|
|||||||
aiwin->session->provider_name = g_strdup(provider_name);
|
aiwin->session->provider_name = g_strdup(provider_name);
|
||||||
ai_provider_unref(aiwin->session->provider);
|
ai_provider_unref(aiwin->session->provider);
|
||||||
aiwin->session->provider = new_provider;
|
aiwin->session->provider = new_provider;
|
||||||
aiwin->session->provider->ref_count++;
|
ai_provider_ref(aiwin->session->provider);
|
||||||
}
|
}
|
||||||
g_free(aiwin->session->model);
|
g_free(aiwin->session->model);
|
||||||
aiwin->session->model = g_strdup(model);
|
aiwin->session->model = g_strdup(model);
|
||||||
|
|||||||
Reference in New Issue
Block a user