Change char->free to auto_char char for autocleanup

Replace `gchar` and `g_free` to `auto_gchar`
Correct certain  `char` functions/variables to `gchar`

Related to #1819.

Edited by @jubalh.
This commit is contained in:
John Hernandez
2023-07-11 13:23:58 +02:00
parent 245d69deb6
commit e1d137f4e6
62 changed files with 498 additions and 969 deletions

View File

@@ -114,8 +114,8 @@ autocomplete_length(Autocomplete ac)
void
autocomplete_update(Autocomplete ac, char** items)
{
gchar* last_found = NULL;
gchar* search_str = NULL;
auto_gchar gchar* last_found = NULL;
auto_gchar gchar* search_str = NULL;
if (ac->last_found) {
last_found = strdup(ac->last_found->data);
@@ -131,12 +131,10 @@ autocomplete_update(Autocomplete ac, char** items)
if (last_found) {
// NULL if last_found was removed on update.
ac->last_found = g_list_find_custom(ac->items, last_found, (GCompareFunc)strcmp);
free(last_found);
}
if (search_str) {
ac->search_str = strdup(search_str);
free(search_str);
}
}

View File

@@ -52,9 +52,7 @@ static gchar* account_jid = NULL;
static void
_bookmark_ignore_load()
{
gchar* bi_loc;
bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE);
auto_gchar gchar* bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE);
if (g_file_test(bi_loc, G_FILE_TEST_EXISTS)) {
g_chmod(bi_loc, S_IRUSR | S_IWUSR);
@@ -62,24 +60,18 @@ _bookmark_ignore_load()
bookmark_ignore_keyfile = g_key_file_new();
g_key_file_load_from_file(bookmark_ignore_keyfile, bi_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_free(bi_loc);
}
static void
_bookmark_save()
{
gsize g_data_size;
gchar* g_bookmark_ignore_data = g_key_file_to_data(bookmark_ignore_keyfile, &g_data_size, NULL);
auto_gchar gchar* g_bookmark_ignore_data = g_key_file_to_data(bookmark_ignore_keyfile, &g_data_size, NULL);
gchar* bi_loc;
bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE);
auto_gchar gchar* bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE);
g_file_set_contents(bi_loc, g_bookmark_ignore_data, g_data_size, NULL);
g_chmod(bi_loc, S_IRUSR | S_IWUSR);
g_free(bi_loc);
g_free(g_bookmark_ignore_data);
}
void

View File

@@ -163,7 +163,7 @@ http_file_put(void* userdata)
FILE* fh = NULL;
char* err = NULL;
auto_char char* err = NULL;
gchar* content_type_header;
// Optional headers
gchar* auth_header = NULL;
@@ -318,7 +318,6 @@ http_file_put(void* userdata)
}
cons_show_error(msg);
g_free(msg);
free(err);
} else {
if (!upload->cancel) {
msg = g_strdup_printf("Uploading '%s': 100%%", upload->filename);

View File

@@ -51,7 +51,7 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb
}
// copy and strip input of leading/trailing whitespace
char* copy = strdup(inp);
auto_char char* copy = strdup(inp);
g_strstrip(copy);
int inp_size = g_utf8_strlen(copy, -1);
@@ -135,8 +135,6 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb
tokens = g_slist_append(tokens, g_strndup(token_start, token_size));
}
free(copy);
int num = g_slist_length(tokens) - 1;
// if num args not valid return NULL