fix(ai): fix provider_name leak and const-cast in cmd_ai_start
Some checks failed
CI Code / Check spelling (pull_request) Successful in 55s
CI Code / Linux (arch) (pull_request) Failing after 3m25s
CI Code / Check coding style (pull_request) Successful in 1m38s
CI Code / Linux (debian) (pull_request) Successful in 4m42s
CI Code / Code Coverage (pull_request) Successful in 2m50s
CI Code / Linux (ubuntu) (pull_request) Successful in 8m12s
Some checks failed
CI Code / Check spelling (pull_request) Successful in 55s
CI Code / Linux (arch) (pull_request) Failing after 3m25s
CI Code / Check coding style (pull_request) Successful in 1m38s
CI Code / Linux (debian) (pull_request) Successful in 4m42s
CI Code / Code Coverage (pull_request) Successful in 2m50s
CI Code / Linux (ubuntu) (pull_request) Successful in 8m12s
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>]
|
||||
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* model = "gpt-4o";
|
||||
|
||||
if (provider_model) {
|
||||
const gchar* slash = strchr(provider_model, '/');
|
||||
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;
|
||||
} else {
|
||||
// Just a model name, use default provider
|
||||
|
||||
Reference in New Issue
Block a user