From 93ad7379e2173dd4a3baa39f887526609a95defc Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Thu, 30 Apr 2026 19:09:46 +0000 Subject: [PATCH] fix(ai): align ai_list_providers with documented contract Remove ai_provider_ref() from ai_list_providers() so the returned providers do not need to be unref'd by the caller. This matches the header docstring which states "caller must not free the list or providers". Also update all callers (cmd_ai_providers, tests) to remove redundant ai_provider_unref() calls. --- src/ai/ai_client.c | 2 +- src/ai/ai_client.h | 3 ++- src/command/cmd_funcs.c | 1 - tests/unittests/test_ai_client.c | 10 ++-------- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/ai/ai_client.c b/src/ai/ai_client.c index 9e27bffc..83201450 100644 --- a/src/ai/ai_client.c +++ b/src/ai/ai_client.c @@ -328,7 +328,7 @@ ai_list_providers(void) g_hash_table_iter_init(&iter, providers); while (g_hash_table_iter_next(&iter, &key, &value)) { - result = g_list_append(result, ai_provider_ref((AIProvider*)value)); + result = g_list_append(result, value); } return result; diff --git a/src/ai/ai_client.h b/src/ai/ai_client.h index 870ec766..c6aaeca1 100644 --- a/src/ai/ai_client.h +++ b/src/ai/ai_client.h @@ -97,7 +97,8 @@ void ai_provider_unref(AIProvider* provider); /** * List all configured providers. - * @return GList of AIProvider* (caller must not free the list or providers) + * @return GList of AIProvider* (caller must not free the list or providers, + * and must not unref the returned providers) */ GList* ai_list_providers(void); diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index d0a798cd..2b0c42b5 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -10929,7 +10929,6 @@ cmd_ai_providers(ProfWin* window, const char* const command, gchar** args) } cons_show(""); g_free(key); - ai_provider_unref(provider); } g_list_free(providers); diff --git a/tests/unittests/test_ai_client.c b/tests/unittests/test_ai_client.c index abc40886..d0a38cb6 100644 --- a/tests/unittests/test_ai_client.c +++ b/tests/unittests/test_ai_client.c @@ -78,10 +78,7 @@ test_ai_list_providers(void** state) assert_non_null(providers); assert_int_equal(2, g_list_length(providers)); /* openai and perplexity */ - /* Free list and unref providers (ai_list_providers returns ref'd providers) */ - for (GList* l = providers; l; l = g_list_next(l)) { - ai_provider_unref(l->data); - } + /* Free list (ai_list_providers returns non-ref'd providers; caller must not unref) */ g_list_free(providers); /* Add another provider */ @@ -89,10 +86,7 @@ test_ai_list_providers(void** state) providers = ai_list_providers(); assert_int_equal(3, g_list_length(providers)); - /* Free list and unref providers */ - for (GList* l = providers; l; l = g_list_next(l)) { - ai_provider_unref(l->data); - } + /* Free list */ g_list_free(providers); }