mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-31 13:06:22 +00:00
fix(ai): fix provider_name leak and const-cast in cmd_ai_start
Use auto_gchar temporary for g_strndup result in cmd_ai_start to prevent memory leak. Fix const-cast warning by using a proper non-const temporary variable.
This commit is contained in:
@@ -10760,13 +10760,15 @@ cmd_ai_start(ProfWin* window, const char* const command, gchar** args)
|
|||||||
// /ai start [<provider>/<model>]
|
// /ai start [<provider>/<model>]
|
||||||
const gchar* provider_model = (g_strv_length(args) >= 2) ? args[1] : NULL;
|
const gchar* provider_model = (g_strv_length(args) >= 2) ? args[1] : NULL;
|
||||||
|
|
||||||
|
auto_gchar gchar* owned_provider_name = NULL;
|
||||||
const gchar* provider_name = "openai";
|
const gchar* provider_name = "openai";
|
||||||
const gchar* model = "gpt-4o";
|
const gchar* model = "gpt-4o";
|
||||||
|
|
||||||
if (provider_model) {
|
if (provider_model) {
|
||||||
const gchar* slash = strchr(provider_model, '/');
|
const gchar* slash = strchr(provider_model, '/');
|
||||||
if (slash) {
|
if (slash) {
|
||||||
provider_name = g_strndup(provider_model, slash - provider_model);
|
owned_provider_name = g_strndup(provider_model, slash - provider_model);
|
||||||
|
provider_name = owned_provider_name;
|
||||||
model = slash + 1;
|
model = slash + 1;
|
||||||
} else {
|
} else {
|
||||||
// Just a model name, use default provider
|
// Just a model name, use default provider
|
||||||
|
|||||||
Reference in New Issue
Block a user