g_free() to auto_gfree, introduce auto_guchar

Fix 11 potential mem leaks in theme.c
This commit is contained in:
John Hernandez
2023-07-13 17:04:59 +02:00
parent 3a4cd7da48
commit 8304ac86ff
39 changed files with 145 additions and 233 deletions

View File

@@ -562,10 +562,9 @@ _inp_rl_startup_hook(void)
rl_variable_bind("disable-completion", "on");
// check for and load ~/.config/profanity/inputrc
gchar* inputrc = files_get_inputrc_file();
auto_gchar gchar* inputrc = files_get_inputrc_file();
if (inputrc) {
rl_read_init_file(inputrc);
g_free(inputrc);
}
return 0;
@@ -948,7 +947,7 @@ _inp_rl_send_to_editor(int count, int key)
return 0;
}
gchar* message = NULL;
auto_gchar gchar* message = NULL;
if (get_message_from_editor(rl_line_buffer, &message)) {
return 0;
@@ -958,7 +957,6 @@ _inp_rl_send_to_editor(int count, int key)
ui_resize();
rl_point = rl_end;
rl_forced_update_display();
g_free(message);
return 0;
}

View File

@@ -77,9 +77,8 @@ notifier_uninit(void)
void
notify_typing(const char* const name)
{
gchar* message = g_strdup_printf("%s: typing…", name);
auto_gchar gchar* message = g_strdup_printf("%s: typing…", name);
notify(message, 10000, "Incoming message");
g_free(message);
}
void

View File

@@ -79,9 +79,8 @@ _get_icons(void)
#endif /* ICONS_PATH */
gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
auto_gchar gchar* icons_dir_s = files_get_config_path(DIR_ICONS);
icons_dir = g_string_new(icons_dir_s);
g_free(icons_dir_s);
GError* err = NULL;
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {

View File

@@ -691,12 +691,12 @@ win_page_down(ProfWin* window)
if ((*page_start == y || (*page_start == page_space && *page_start >= y)) && window->type == WIN_CHAT) {
int bf_size = buffer_size(window->layout->buffer);
if (bf_size > 0) {
char* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
auto_gchar gchar* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);
GDateTime* now = g_date_time_new_now_local();
char* end = g_date_time_format_iso8601(now);
gchar* end = g_date_time_format_iso8601(now);
// end is free'd inside
chatwin_db_history((ProfChatWin*)window, start, end, FALSE);
g_free(start);
g_date_time_unref(now);
}
}
@@ -1788,7 +1788,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
int colour = theme_attrs(THEME_ME);
size_t indent = 0;
char* time_pref = NULL;
auto_gchar gchar* time_pref = NULL;
switch (window->type) {
case WIN_CHAT:
time_pref = prefs_get_string(PREF_TIME_CHAT);
@@ -1810,13 +1810,12 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
break;
}
gchar* date_fmt = NULL;
auto_gchar gchar* date_fmt = NULL;
if (g_strcmp0(time_pref, "off") == 0 || time == NULL) {
date_fmt = g_strdup("");
} else {
date_fmt = g_date_time_format(time, time_pref);
}
g_free(time_pref);
assert(date_fmt != NULL);
if (strlen(date_fmt) != 0) {
@@ -1903,8 +1902,6 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
wattroff(window->layout->win, theme_attrs(theme_item));
}
}
g_free(date_fmt);
}
static void
@@ -2309,21 +2306,17 @@ win_quote_autocomplete(ProfWin* window, const char* const input, gboolean previo
return NULL;
}
char* result = autocomplete_complete(window->quotes_ac, input + 1, FALSE, previous);
auto_gchar gchar* result = autocomplete_complete(window->quotes_ac, input + 1, FALSE, previous);
if (result == NULL) {
return NULL;
}
gchar** parts = g_strsplit(result, "\n", -1);
gchar* quoted_result = g_strjoinv("\n> ", parts);
auto_gcharv gchar** parts = g_strsplit(result, "\n", -1);
auto_gchar gchar* quoted_result = g_strjoinv("\n> ", parts);
GString* replace_with = g_string_new("> ");
g_string_append(replace_with, quoted_result);
g_string_append(replace_with, "\n");
g_free(result);
g_free(quoted_result);
g_strfreev(parts);
return g_string_free(replace_with, FALSE);
}

View File

@@ -1318,7 +1318,7 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
g_regex_match(regex, message->plain, 0, &match_info);
while (g_match_info_matches(match_info)) {
gchar* word = g_match_info_fetch(match_info, 0);
auto_gchar gchar* word = g_match_info_fetch(match_info, 0);
if (flip) {
autocomplete_add_unsorted(win->urls_ac, word, FALSE);
@@ -1328,7 +1328,6 @@ wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message, con
// for people who run profanity a long time, we don't want to waste a lot of memory
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
g_free(word);
g_match_info_next(match_info, NULL);
}