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

@@ -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);
}