1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Cleanup g_strfreev() to auto_gcharv

Include some additional minor cleanups
This commit is contained in:
John Hernandez 2023-07-13 16:31:31 +02:00
parent 029f1caa52
commit 865a056315
16 changed files with 165 additions and 234 deletions

View File

@ -3210,14 +3210,14 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
return NULL; return NULL;
} }
gchar** split = g_strsplit(input, " ", 0); auto_gcharv gchar** split = g_strsplit(input, " ", 0);
if (g_strv_length(split) == 3) { if (g_strv_length(split) == 3) {
char* field_tag = split[0] + 1; char* field_tag = split[0] + 1;
if (form_tag_exists(form, field_tag)) { if (form_tag_exists(form, field_tag)) {
form_field_type_t field_type = form_get_field_type(form, field_tag); form_field_type_t field_type = form_get_field_type(form, field_tag);
Autocomplete value_ac = form_get_value_ac(form, field_tag); Autocomplete value_ac = form_get_value_ac(form, field_tag);
;
GString* beginning = g_string_new(split[0]); GString* beginning = g_string_new(split[0]);
g_string_append(beginning, " "); g_string_append(beginning, " ");
g_string_append(beginning, split[1]); g_string_append(beginning, split[1]);
@ -3225,10 +3225,8 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0)) if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0))
&& field_type == FIELD_LIST_MULTI) { && field_type == FIELD_LIST_MULTI) {
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous); found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) { } else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous); found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) { } else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) {
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous); found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
} }
@ -3241,7 +3239,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
if (form_tag_exists(form, field_tag)) { if (form_tag_exists(form, field_tag)) {
form_field_type_t field_type = form_get_field_type(form, field_tag); form_field_type_t field_type = form_get_field_type(form, field_tag);
Autocomplete value_ac = form_get_value_ac(form, field_tag); Autocomplete value_ac = form_get_value_ac(form, field_tag);
;
switch (field_type) { switch (field_type) {
case FIELD_BOOLEAN: case FIELD_BOOLEAN:
@ -3261,8 +3258,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
} }
} }
g_strfreev(split);
return found; return found;
} }

View File

@ -2768,7 +2768,7 @@ _cmd_index(const Command* cmd)
index_source = g_string_append(index_source, " "); index_source = g_string_append(index_source, " ");
} }
gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL); auto_gcharv gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
g_string_free(index_source, TRUE); g_string_free(index_source, TRUE);
GString* index = g_string_new(""); GString* index = g_string_new("");
@ -2776,7 +2776,6 @@ _cmd_index(const Command* cmd)
index = g_string_append(index, tokens[i]); index = g_string_append(index, tokens[i]);
index = g_string_append(index, " "); index = g_string_append(index, " ");
} }
g_strfreev(tokens);
return g_string_free(index, FALSE); return g_string_free(index, FALSE);
} }
@ -2786,7 +2785,7 @@ cmd_search_index_any(char* term)
{ {
GList* results = NULL; GList* results = NULL;
gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL); auto_gcharv gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
int terms_len = g_strv_length(processed_terms); int terms_len = g_strv_length(processed_terms);
for (int i = 0; i < terms_len; i++) { for (int i = 0; i < terms_len; i++) {
@ -2802,8 +2801,6 @@ cmd_search_index_any(char* term)
g_list_free(index_keys); g_list_free(index_keys);
} }
g_strfreev(processed_terms);
return results; return results;
} }
@ -2812,7 +2809,7 @@ cmd_search_index_all(char* term)
{ {
GList* results = NULL; GList* results = NULL;
gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL); auto_gcharv gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
int terms_len = g_strv_length(terms); int terms_len = g_strv_length(terms);
GList* commands = g_hash_table_get_keys(search_index); GList* commands = g_hash_table_get_keys(search_index);
@ -2833,7 +2830,6 @@ cmd_search_index_all(char* term)
} }
g_list_free(commands); g_list_free(commands);
g_strfreev(terms);
return results; return results;
} }

View File

@ -505,9 +505,8 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
gboolean gboolean
cmd_account_list(ProfWin* window, const char* const command, gchar** args) cmd_account_list(ProfWin* window, const char* const command, gchar** args)
{ {
gchar** accounts = accounts_get_list(); auto_gcharv gchar** accounts = accounts_get_list();
cons_show_account_list(accounts); cons_show_account_list(accounts);
g_strfreev(accounts);
return TRUE; return TRUE;
} }
@ -4839,9 +4838,8 @@ cmd_bookmark_ignore(ProfWin* window, const char* const command, gchar** args)
// `/bookmark ignore` lists them // `/bookmark ignore` lists them
if (args[1] == NULL) { if (args[1] == NULL) {
gsize len = 0; gsize len = 0;
gchar** list = bookmark_ignore_list(&len); auto_gcharv gchar** list = bookmark_ignore_list(&len);
cons_show_bookmarks_ignore(list, len); cons_show_bookmarks_ignore(list, len);
g_strfreev(list);
return TRUE; return TRUE;
} }
@ -8479,18 +8477,16 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
{ {
if (g_str_has_prefix(command, "/field") && window->type == WIN_CONFIG) { if (g_str_has_prefix(command, "/field") && window->type == WIN_CONFIG) {
gboolean result = FALSE; gboolean result = FALSE;
gchar** args = parse_args_with_freetext(inp, 1, 2, &result); auto_gcharv gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
if (!result) { if (!result) {
win_println(window, THEME_DEFAULT, "!", "Invalid command, see /form help"); win_println(window, THEME_DEFAULT, "!", "Invalid command, see /form help");
result = TRUE; result = TRUE;
} else { } else {
gchar** tokens = g_strsplit(inp, " ", 2); auto_gcharv gchar** tokens = g_strsplit(inp, " ", 2);
char* field = tokens[0] + 1; char* field = tokens[0] + 1;
result = cmd_form_field(window, field, args); result = cmd_form_field(window, field, args);
g_strfreev(tokens);
} }
g_strfreev(args);
return result; return result;
} }
@ -8498,7 +8494,7 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
gboolean result = FALSE; gboolean result = FALSE;
if (cmd) { if (cmd) {
gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result); auto_gcharv gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
if (result == FALSE) { if (result == FALSE) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func); ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE; return TRUE;
@ -8507,20 +8503,17 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
int i = 0; int i = 0;
while (cmd->sub_funcs[i].cmd) { while (cmd->sub_funcs[i].cmd) {
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i].cmd) == 0) { if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i].cmd) == 0) {
result = cmd->sub_funcs[i].func(window, command, args); return cmd->sub_funcs[i].func(window, command, args);
goto out;
} }
i++; i++;
} }
} }
if (!cmd->func) { if (!cmd->func) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func); ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
result = TRUE; return TRUE;
goto out;
} }
result = cmd->func(window, command, args); result = cmd->func(window, command, args);
out:
g_strfreev(args);
return result; return result;
} else if (plugins_run_command(inp)) { } else if (plugins_run_command(inp)) {
return TRUE; return TRUE;
@ -9543,15 +9536,13 @@ _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* p
void void
_url_external_method(const char* cmd_template, const char* url, gchar* filename) _url_external_method(const char* cmd_template, const char* url, gchar* filename)
{ {
gchar** argv = format_call_external_argv(cmd_template, url, filename); auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);
if (!call_external(argv)) { if (!call_external(argv)) {
cons_show_error("Unable to call external executable for url: check the logs for more information."); cons_show_error("Unable to call external executable for url: check the logs for more information.");
} else { } else {
cons_show("URL '%s' has been called with '%s'.", url, cmd_template); cons_show("URL '%s' has been called with '%s'.", url, cmd_template);
} }
g_strfreev(argv);
} }
gboolean gboolean

View File

@ -78,7 +78,7 @@ accounts_load(void)
// create the logins searchable list for autocompletion // create the logins searchable list for autocompletion
gsize naccounts; gsize naccounts;
gchar** account_names = g_key_file_get_groups(accounts, &naccounts); auto_gcharv gchar** account_names = g_key_file_get_groups(accounts, &naccounts);
for (gsize i = 0; i < naccounts; i++) { for (gsize i = 0; i < naccounts; i++) {
autocomplete_add(all_ac, account_names[i]); autocomplete_add(all_ac, account_names[i]);
@ -86,8 +86,6 @@ accounts_load(void)
autocomplete_add(enabled_ac, account_names[i]); autocomplete_add(enabled_ac, account_names[i]);
} }
} }
g_strfreev(account_names);
} }
void void
@ -245,30 +243,27 @@ accounts_get_account(const char* const name)
gsize length; gsize length;
GList* otr_manual = NULL; GList* otr_manual = NULL;
gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL); auto_gcharv gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
if (manual) { if (manual) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
otr_manual = g_list_append(otr_manual, strdup(manual[i])); otr_manual = g_list_append(otr_manual, strdup(manual[i]));
} }
g_strfreev(manual);
} }
GList* otr_opportunistic = NULL; GList* otr_opportunistic = NULL;
gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL); auto_gcharv gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
if (opportunistic) { if (opportunistic) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i])); otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
} }
g_strfreev(opportunistic);
} }
GList* otr_always = NULL; GList* otr_always = NULL;
gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL); auto_gcharv gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
if (always) { if (always) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
otr_always = g_list_append(otr_always, strdup(always[i])); otr_always = g_list_append(otr_always, strdup(always[i]));
} }
g_strfreev(always);
} }
gchar* omemo_policy = NULL; gchar* omemo_policy = NULL;
@ -277,39 +272,35 @@ accounts_get_account(const char* const name)
} }
GList* omemo_enabled = NULL; GList* omemo_enabled = NULL;
gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL); auto_gcharv gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
if (omemo_enabled_list) { if (omemo_enabled_list) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
omemo_enabled = g_list_append(omemo_enabled, strdup(omemo_enabled_list[i])); omemo_enabled = g_list_append(omemo_enabled, strdup(omemo_enabled_list[i]));
} }
g_strfreev(omemo_enabled_list);
} }
GList* omemo_disabled = NULL; GList* omemo_disabled = NULL;
gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL); auto_gcharv gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
if (omemo_disabled_list) { if (omemo_disabled_list) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
omemo_disabled = g_list_append(omemo_disabled, strdup(omemo_disabled_list[i])); omemo_disabled = g_list_append(omemo_disabled, strdup(omemo_disabled_list[i]));
} }
g_strfreev(omemo_disabled_list);
} }
GList* ox_enabled = NULL; GList* ox_enabled = NULL;
gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL); auto_gcharv gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL);
if (ox_enabled_list) { if (ox_enabled_list) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
ox_enabled = g_list_append(ox_enabled, strdup(ox_enabled_list[i])); ox_enabled = g_list_append(ox_enabled, strdup(ox_enabled_list[i]));
} }
g_strfreev(ox_enabled_list);
} }
GList* pgp_enabled = NULL; GList* pgp_enabled = NULL;
gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL); auto_gcharv gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL);
if (pgp_enabled_list) { if (pgp_enabled_list) {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
pgp_enabled = g_list_append(pgp_enabled, strdup(pgp_enabled_list[i])); pgp_enabled = g_list_append(pgp_enabled, strdup(pgp_enabled_list[i]));
} }
g_strfreev(pgp_enabled_list);
} }
gchar* pgp_keyid = NULL; gchar* pgp_keyid = NULL;

View File

@ -34,6 +34,7 @@
*/ */
#include "config.h" #include "config.h"
#include "common.h"
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
@ -42,7 +43,7 @@ gboolean
conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item) conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
{ {
gsize length; gsize length;
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL); auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
GList* glist = NULL; GList* glist = NULL;
// list found // list found
@ -81,7 +82,6 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
g_key_file_set_string_list(keyfile, group, key, new_list, 1); g_key_file_set_string_list(keyfile, group, key, new_list, 1);
} }
g_strfreev(list);
g_list_free_full(glist, g_free); g_list_free_full(glist, g_free);
return TRUE; return TRUE;
@ -91,10 +91,12 @@ gboolean
conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item) conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
{ {
gsize length; gsize length;
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL); auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
gboolean deleted = FALSE; gboolean deleted = FALSE;
if (list) { if (!list) {
return FALSE;
}
int i = 0; int i = 0;
GList* glist = NULL; GList* glist = NULL;
@ -126,9 +128,6 @@ conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char*
} }
g_list_free_full(glist, g_free); g_list_free_full(glist, g_free);
}
g_strfreev(list);
return deleted; return deleted;
} }

View File

@ -216,12 +216,11 @@ _prefs_load(void)
room_trigger_ac = autocomplete_new(); room_trigger_ac = autocomplete_new();
gsize len = 0; gsize len = 0;
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
autocomplete_add(room_trigger_ac, triggers[i]); autocomplete_add(room_trigger_ac, triggers[i]);
} }
g_strfreev(triggers);
} }
/* Clean up after _prefs_load() */ /* Clean up after _prefs_load() */
@ -333,7 +332,7 @@ prefs_message_get_triggers(const char* const message)
auto_gchar gchar* message_lower = g_utf8_strdown(message, -1); auto_gchar gchar* message_lower = g_utf8_strdown(message, -1);
gsize len = 0; gsize len = 0;
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
auto_gchar gchar* trigger_lower = g_utf8_strdown(triggers[i], -1); auto_gchar gchar* trigger_lower = g_utf8_strdown(triggers[i], -1);
@ -342,8 +341,6 @@ prefs_message_get_triggers(const char* const message)
} }
} }
g_strfreev(triggers);
return result; return result;
} }
@ -862,12 +859,6 @@ prefs_remove_plugin(const char* const name)
_save_prefs(); _save_prefs();
} }
void
prefs_free_plugins(gchar** plugins)
{
g_strfreev(plugins);
}
void void
prefs_set_occupants_size(gint value) prefs_set_occupants_size(gint value)
{ {
@ -1316,14 +1307,12 @@ prefs_get_room_notify_triggers(void)
{ {
GList* result = NULL; GList* result = NULL;
gsize len = 0; gsize len = 0;
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
result = g_list_append(result, strdup(triggers[i])); result = g_list_append(result, strdup(triggers[i]));
} }
g_strfreev(triggers);
return result; return result;
} }
@ -1665,7 +1654,7 @@ prefs_get_aliases(void)
} else { } else {
GList* result = NULL; GList* result = NULL;
gsize len; gsize len;
gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL); auto_gcharv gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
char* name = keys[i]; char* name = keys[i];
@ -1680,8 +1669,6 @@ prefs_get_aliases(void)
} }
} }
g_strfreev(keys);
return result; return result;
} }
} }

View File

@ -253,7 +253,6 @@ gint prefs_get_autoxa_time(void);
void prefs_set_autoxa_time(gint value); void prefs_set_autoxa_time(gint value);
gchar** prefs_get_plugins(void); gchar** prefs_get_plugins(void);
void prefs_free_plugins(gchar** plugins);
void prefs_add_plugin(const char* const name); void prefs_add_plugin(const char* const name);
void prefs_remove_plugin(const char* const name); void prefs_remove_plugin(const char* const name);

View File

@ -71,12 +71,11 @@ tlscerts_init(void)
certs_ac = autocomplete_new(); certs_ac = autocomplete_new();
gsize len = 0; gsize len = 0;
gchar** groups = g_key_file_get_groups(tlscerts, &len); auto_gcharv gchar** groups = g_key_file_get_groups(tlscerts, &len);
for (int i = 0; i < g_strv_length(groups); i++) { for (int i = 0; i < g_strv_length(groups); i++) {
autocomplete_add(certs_ac, groups[i]); autocomplete_add(certs_ac, groups[i]);
} }
g_strfreev(groups);
current_fp = NULL; current_fp = NULL;
} }
@ -116,7 +115,7 @@ tlscerts_list(void)
{ {
GList* res = NULL; GList* res = NULL;
gsize len = 0; gsize len = 0;
gchar** groups = g_key_file_get_groups(tlscerts, &len); auto_gcharv gchar** groups = g_key_file_get_groups(tlscerts, &len);
for (int i = 0; i < g_strv_length(groups); i++) { for (int i = 0; i < g_strv_length(groups); i++) {
char* fingerprint = strdup(groups[i]); char* fingerprint = strdup(groups[i]);
@ -135,10 +134,6 @@ tlscerts_list(void)
res = g_list_append(res, cert); res = g_list_append(res, cert);
} }
if (groups) {
g_strfreev(groups);
}
return res; return res;
} }
@ -178,9 +173,9 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
cert->pem = strdup(pem); cert->pem = strdup(pem);
} }
gchar** fields = g_strsplit(subjectname, "/", 0); auto_gcharv gchar** fields = g_strsplit(subjectname, "/", 0);
for (int i = 0; i < g_strv_length(fields); i++) { for (int i = 0; i < g_strv_length(fields); i++) {
gchar** keyval = g_strsplit(fields[i], "=", 2); auto_gcharv gchar** keyval = g_strsplit(fields[i], "=", 2);
if (g_strv_length(keyval) == 2) { if (g_strv_length(keyval) == 2) {
if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) { if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) {
cert->subject_country = strdup(keyval[1]); cert->subject_country = strdup(keyval[1]);
@ -207,13 +202,11 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
cert->subject_email = strdup(keyval[1]); cert->subject_email = strdup(keyval[1]);
} }
} }
g_strfreev(keyval);
} }
g_strfreev(fields);
fields = g_strsplit(issuername, "/", 0); auto_gcharv gchar** fields2 = g_strsplit(issuername, "/", 0);
for (int i = 0; i < g_strv_length(fields); i++) { for (int i = 0; i < g_strv_length(fields2); i++) {
gchar** keyval = g_strsplit(fields[i], "=", 2); auto_gcharv gchar** keyval = g_strsplit(fields2[i], "=", 2);
if (g_strv_length(keyval) == 2) { if (g_strv_length(keyval) == 2) {
if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) { if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) {
cert->issuer_country = strdup(keyval[1]); cert->issuer_country = strdup(keyval[1]);
@ -240,9 +233,7 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
cert->issuer_email = strdup(keyval[1]); cert->issuer_email = strdup(keyval[1]);
} }
} }
g_strfreev(keyval);
} }
g_strfreev(fields);
return cert; return cert;
} }

View File

@ -1319,10 +1319,9 @@ static void
_cut(ProfMessage* message, const char* cut) _cut(ProfMessage* message, const char* cut)
{ {
if (strstr(message->plain, cut)) { if (strstr(message->plain, cut)) {
gchar** split = g_strsplit(message->plain, cut, -1); auto_gcharv gchar** split = g_strsplit(message->plain, cut, -1);
free(message->plain); free(message->plain);
message->plain = g_strjoinv("", split); message->plain = g_strjoinv("", split);
g_strfreev(split);
} }
} }

View File

@ -1597,11 +1597,13 @@ _load_identity(void)
static void static void
_load_trust(void) _load_trust(void)
{ {
char** keys = NULL; auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.trust_keyfile, NULL);
gchar** groups = g_key_file_get_groups(omemo_ctx.trust_keyfile, NULL);
if (groups) { if (!groups) {
int i; return;
for (i = 0; groups[i] != NULL; i++) { }
for (int i = 0; groups[i] != NULL; i++) {
GHashTable* trusted; GHashTable* trusted;
trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]); trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
@ -1610,9 +1612,8 @@ _load_trust(void)
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted); g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
} }
keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL); auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL);
int j; for (int j = 0; keys[j] != NULL; j++) {
for (j = 0; keys[j] != NULL; j++) {
auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL); auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL);
size_t key_len; size_t key_len;
auto_guchar guchar* key = g_base64_decode(key_b64, &key_len); auto_guchar guchar* key = g_base64_decode(key_b64, &key_len);
@ -1620,20 +1621,19 @@ _load_trust(void)
uint32_t device_id = strtoul(keys[j], NULL, 10); uint32_t device_id = strtoul(keys[j], NULL, 10);
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer); g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
} }
g_strfreev(keys);
}
g_strfreev(groups);
} }
} }
static void static void
_load_sessions(void) _load_sessions(void)
{ {
int i;
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.sessions_keyfile, NULL); auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.sessions_keyfile, NULL);
if (groups) {
for (i = 0; groups[i] != NULL; i++) { if (!groups) {
int j; return;
}
for (int i = 0; groups[i] != NULL; i++) {
GHashTable* device_store = NULL; GHashTable* device_store = NULL;
device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]); device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]);
@ -1643,7 +1643,7 @@ _load_sessions(void)
} }
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL); auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL);
for (j = 0; keys[j] != NULL; j++) { for (int j = 0; keys[j] != NULL; j++) {
uint32_t id = strtoul(keys[j], NULL, 10); uint32_t id = strtoul(keys[j], NULL, 10);
auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL); auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL);
size_t record_len; size_t record_len;
@ -1652,17 +1652,18 @@ _load_sessions(void)
g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer); g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer);
} }
} }
}
} }
static void static void
_load_known_devices(void) _load_known_devices(void)
{ {
int i;
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.known_devices_keyfile, NULL); auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.known_devices_keyfile, NULL);
if (groups) {
for (i = 0; groups[i] != NULL; i++) { if (!groups) {
int j; return;
}
for (int i = 0; groups[i] != NULL; i++) {
GHashTable* known_identities = NULL; GHashTable* known_identities = NULL;
known_identities = g_hash_table_lookup(omemo_ctx.known_devices, groups[i]); known_identities = g_hash_table_lookup(omemo_ctx.known_devices, groups[i]);
@ -1672,13 +1673,12 @@ _load_known_devices(void)
} }
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.known_devices_keyfile, groups[i], NULL, NULL); auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.known_devices_keyfile, groups[i], NULL, NULL);
for (j = 0; keys[j] != NULL; j++) { for (int j = 0; keys[j] != NULL; j++) {
uint32_t device_id = strtoul(keys[j], NULL, 10); uint32_t device_id = strtoul(keys[j], NULL, 10);
auto_gchar gchar* fingerprint = g_key_file_get_string(omemo_ctx.known_devices_keyfile, groups[i], keys[j], NULL); auto_gchar gchar* fingerprint = g_key_file_get_string(omemo_ctx.known_devices_keyfile, groups[i], keys[j], NULL);
g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id)); g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
} }
} }
}
} }
static void static void

View File

@ -177,14 +177,13 @@ p_gpg_on_connect(const char* const barejid)
// load each keyid // load each keyid
gsize len = 0; gsize len = 0;
gchar** jids = g_key_file_get_groups(pubkeyfile, &len); auto_gcharv gchar** jids = g_key_file_get_groups(pubkeyfile, &len);
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t error = gpgme_new(&ctx); gpgme_error_t error = gpgme_new(&ctx);
if (error) { if (error) {
log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error)); log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
g_strfreev(jids);
return; return;
} }
@ -212,7 +211,6 @@ p_gpg_on_connect(const char* const barejid)
} }
gpgme_release(ctx); gpgme_release(ctx);
g_strfreev(jids);
_save_pubkeys(); _save_pubkeys();
} }

View File

@ -273,7 +273,7 @@ callbacks_get_window_handler(const char* tag)
gboolean gboolean
plugins_run_command(const char* const input) plugins_run_command(const char* const input)
{ {
gchar** split = g_strsplit(input, " ", -1); auto_gcharv gchar** split = g_strsplit(input, " ", -1);
GList* command_hashes = g_hash_table_get_values(p_commands); GList* command_hashes = g_hash_table_get_values(p_commands);
GList* curr_hash = command_hashes; GList* curr_hash = command_hashes;
@ -283,26 +283,20 @@ plugins_run_command(const char* const input)
PluginCommand* command = g_hash_table_lookup(command_hash, split[0]); PluginCommand* command = g_hash_table_lookup(command_hash, split[0]);
if (command) { if (command) {
gboolean result; gboolean result;
gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result); auto_gcharv gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
if (result == FALSE) { if (result == FALSE) {
ui_invalid_command_usage(command->command_name, NULL); ui_invalid_command_usage(command->command_name, NULL);
g_strfreev(split);
g_list_free(command_hashes);
return TRUE;
} else { } else {
command->callback_exec(command, args); command->callback_exec(command, args);
g_strfreev(split); }
g_strfreev(args);
g_list_free(command_hashes); g_list_free(command_hashes);
return TRUE; return TRUE;
} }
}
curr_hash = g_list_next(curr_hash); curr_hash = g_list_next(curr_hash);
} }
g_list_free(command_hashes); g_list_free(command_hashes);
g_strfreev(split);
return FALSE; return FALSE;
} }

View File

@ -82,8 +82,10 @@ plugins_init(void)
#endif #endif
// load plugins // load plugins
gchar** plugins_pref = prefs_get_plugins(); auto_gcharv gchar** plugins_pref = prefs_get_plugins();
if (plugins_pref) { if (!plugins_pref) {
return;
}
for (int i = 0; i < g_strv_length(plugins_pref); i++) { for (int i = 0; i < g_strv_length(plugins_pref); i++) {
gboolean loaded = FALSE; gboolean loaded = FALSE;
gchar* filename = plugins_pref[i]; gchar* filename = plugins_pref[i];
@ -121,11 +123,6 @@ plugins_init(void)
curr = g_list_next(curr); curr = g_list_next(curr);
} }
g_list_free(values); g_list_free(values);
}
prefs_free_plugins(plugins_pref);
return;
} }
void void

View File

@ -378,7 +378,7 @@ _caps_by_ver(const char* const ver)
auto_gchar gchar* os_version = g_key_file_get_string(cache, ver, "os_version", NULL); auto_gchar gchar* os_version = g_key_file_get_string(cache, ver, "os_version", NULL);
gsize features_len = 0; gsize features_len = 0;
gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL); auto_gcharv gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
GSList* features = NULL; GSList* features = NULL;
if (features_list && features_len > 0) { if (features_list && features_len > 0) {
for (int i = 0; i < features_len; i++) { for (int i = 0; i < features_len; i++) {
@ -391,9 +391,6 @@ _caps_by_ver(const char* const ver)
software, software_version, os, os_version, software, software_version, os, os_version,
features); features);
if (features_list) {
g_strfreev(features_list);
}
g_slist_free(features); g_slist_free(features);
return result; return result;

View File

@ -877,7 +877,7 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
} }
// validate sha1 // validate sha1
gchar** split = g_strsplit(node, "#", -1); auto_gcharv gchar** split = g_strsplit(node, "#", -1);
char* given_sha1 = split[1]; char* given_sha1 = split[1];
auto_gchar gchar* generated_sha1 = stanza_create_caps_sha1_from_query(query); auto_gchar gchar* generated_sha1 = stanza_create_caps_sha1_from_query(query);
@ -901,8 +901,6 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
caps_map_jid_to_ver(from, given_sha1); caps_map_jid_to_ver(from, given_sha1);
} }
g_strfreev(split);
return 0; return 0;
} }

View File

@ -1350,7 +1350,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
} }
if (data->open) { if (data->open) {
gchar** argv; auto_gcharv gchar** argv;
gint argc; gint argc;
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD); auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
@ -1366,7 +1366,6 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
if (!call_external(argv)) { if (!call_external(argv)) {
cons_show_error("Unable to execute command"); cons_show_error("Unable to execute command");
} }
g_strfreev(argv);
} }
} }