diff options
author | Antenore Gatta <antenore@simbiosi.org> | 2020-06-18 16:19:21 +0300 |
---|---|---|
committer | Antenore Gatta <antenore@simbiosi.org> | 2020-06-18 16:19:21 +0300 |
commit | 6cb6d14327959be27f72df787c7f014242b66561 (patch) | |
tree | 996980d86c4080459ee804efbe1aab5e2305a403 /src | |
parent | 698cdc0c777c19c94196ebf158628f4c1267a359 (diff) |
Using g_autofree when possible
Signed-off-by: Antenore Gatta <antenore@simbiosi.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/remmina_file_manager.c | 6 | ||||
-rw-r--r-- | src/remmina_log.c | 8 | ||||
-rw-r--r-- | src/remmina_pref.c | 27 | ||||
-rw-r--r-- | src/remmina_stats.c | 6 |
4 files changed, 22 insertions, 25 deletions
diff --git a/src/remmina_file_manager.c b/src/remmina_file_manager.c index 361636c50..d7a5311a9 100644 --- a/src/remmina_file_manager.c +++ b/src/remmina_file_manager.c @@ -278,6 +278,7 @@ GNode *remmina_file_manager_get_group_tree(void) TRACE_CALL(__func__); gchar filename[MAX_PATH_LEN]; GDir *dir; + g_autofree gchar *datadir = NULL; const gchar *name; RemminaFile *remminafile; const gchar *group; @@ -285,14 +286,15 @@ GNode *remmina_file_manager_get_group_tree(void) root = g_node_new(NULL); - dir = g_dir_open(remmina_file_get_datadir(), 0, NULL); + datadir = g_strdup(remmina_file_get_datadir()); + dir = g_dir_open(datadir, 0, NULL); if (dir == NULL) return root; while ((name = g_dir_read_name(dir)) != NULL) { if (!g_str_has_suffix(name, ".remmina")) continue; - g_snprintf(filename, MAX_PATH_LEN, "%s/%s", remmina_file_get_datadir(), name); + g_snprintf(filename, MAX_PATH_LEN, "%s/%s", datadir, name); remminafile = remmina_file_load(filename); if (remminafile) { group = remmina_file_get_string(remminafile, "group"); diff --git a/src/remmina_log.c b/src/remmina_log.c index 4dc6b659f..6da990bf3 100644 --- a/src/remmina_log.c +++ b/src/remmina_log.c @@ -201,15 +201,17 @@ void _remmina_debug(const gchar *fun, const gchar *fmt, ...) va_start(args, fmt); text = g_strdup_vprintf(fmt, args); va_end(args); + g_autofree gchar *buf = g_strconcat("(", fun, ") - ", text, NULL); - g_debug ("%s", g_strdup(buf)); + g_debug ("%s", buf); - buf = g_strconcat (buf, "\n", NULL); + /* freed in remmina_log_print_real */ + gchar *bufn = g_strconcat(buf, "\n", NULL); if (!log_window) return; - IDLE_ADD(remmina_log_print_real, g_strdup(buf)); + IDLE_ADD(remmina_log_print_real, bufn); } void remmina_log_printf(const gchar *fmt, ...) diff --git a/src/remmina_pref.c b/src/remmina_pref.c index 6c1e41c6c..0f60a9a63 100644 --- a/src/remmina_pref.c +++ b/src/remmina_pref.c @@ -75,7 +75,7 @@ static void remmina_pref_gen_secret(void) gint i; GDateTime *gtime; GKeyFile *gkeyfile; - gchar *content; + g_autofree gchar *content = NULL; gsize length; gtime = g_date_time_new_now_utc(); @@ -93,7 +93,6 @@ static void remmina_pref_gen_secret(void) g_file_set_contents(remmina_pref_file, content, length, NULL); g_key_file_free(gkeyfile); - g_free(content); } static guint remmina_pref_get_keyval_from_str(const gchar *str) @@ -120,7 +119,7 @@ static void remmina_pref_init_keymap(void) gchar **keys; gchar **kptr; gsize nkeys; - gchar *value; + g_autofree gchar *value = NULL; guint *table; guint *tableptr; guint k1, k2; @@ -153,7 +152,6 @@ static void remmina_pref_init_keymap(void) if (k1) { value = g_key_file_get_string(gkeyfile, *gptr, *kptr, NULL); k2 = remmina_pref_get_keyval_from_str(value); - g_free(value); *tableptr++ = k1; *tableptr++ = k2; } @@ -225,9 +223,9 @@ void remmina_pref_init(void) gchar *remmina_dir; const gchar *filename = "remmina.pref"; const gchar *colors_filename = "remmina.colors"; - gchar *remmina_colors_file; + g_autofree gchar *remmina_colors_file = NULL; GDir *dir; - gchar *legacy = ".remmina"; + const gchar *legacy = ".remmina"; int i; remmina_dir = g_build_path("/", g_get_user_config_dir(), "remmina", NULL); @@ -736,7 +734,7 @@ gboolean remmina_pref_save(void) } GKeyFile *gkeyfile; GError *error = NULL; - gchar *content; + g_autofree gchar *content = NULL; gsize length; gkeyfile = g_key_file_new(); @@ -853,11 +851,9 @@ gboolean remmina_pref_save(void) g_warning("remmina_pref_save error: %s", error->message); g_clear_error(&error); g_key_file_free(gkeyfile); - g_free(content); return FALSE; } g_key_file_free(gkeyfile); - g_free(content); return TRUE; } @@ -867,8 +863,8 @@ void remmina_pref_add_recent(const gchar *protocol, const gchar *server) RemminaStringArray *array; GKeyFile *gkeyfile; gchar key[20]; - gchar *val; - gchar *content; + g_autofree gchar *val = NULL; + g_autofree gchar *content = NULL; gsize length; if (remmina_pref.recent_maximum <= 0 || server == NULL || server[0] == 0) @@ -891,13 +887,11 @@ void remmina_pref_add_recent(const gchar *protocol, const gchar *server) /* Save */ val = remmina_string_array_to_string(array); g_key_file_set_string(gkeyfile, "remmina_pref", key, val); - g_free(val); content = g_key_file_to_data(gkeyfile, &length, NULL); g_file_set_contents(remmina_pref_file, content, length, NULL); g_key_file_free(gkeyfile); - g_free(content); } gchar * @@ -906,7 +900,7 @@ remmina_pref_get_recent(const gchar *protocol) TRACE_CALL(__func__); GKeyFile *gkeyfile; gchar key[20]; - gchar *val; + gchar *val = NULL; gkeyfile = g_key_file_new(); @@ -926,7 +920,7 @@ void remmina_pref_clear_recent(void) GKeyFile *gkeyfile; gchar **keys; gint i; - gchar *content; + g_autofree gchar *content = NULL; gsize length; gkeyfile = g_key_file_new(); @@ -944,7 +938,6 @@ void remmina_pref_clear_recent(void) g_file_set_contents(remmina_pref_file, content, length, NULL); g_key_file_free(gkeyfile); - g_free(content); } guint remmina_pref_keymap_get_keyval(const gchar *keymap, guint keyval) @@ -1061,7 +1054,7 @@ gchar *remmina_pref_get_value(const gchar *key) { TRACE_CALL(__func__); GKeyFile *gkeyfile; - gchar *value; + gchar *value = NULL; gkeyfile = g_key_file_new(); g_key_file_load_from_file(gkeyfile, remmina_pref_file, G_KEY_FILE_NONE, NULL); diff --git a/src/remmina_stats.c b/src/remmina_stats.c index 22467304f..23431951f 100644 --- a/src/remmina_stats.c +++ b/src/remmina_stats.c @@ -554,7 +554,7 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da gint count = 0; gpointer pcount, kpo; - gpointer pdate, kdo; + gpointer pdate; gchar *hday, *hmonth, *hyear; gchar *pday, *pmonth, *pyear; @@ -593,7 +593,7 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da } g_hash_table_replace(pdata->proto_count, g_strdup(pdata->protocol), GINT_TO_POINTER(count)); pdate = NULL; - if (g_hash_table_lookup_extended(pdata->proto_date, pdata->protocol, &kdo, &pdate)) { + if (g_hash_table_lookup_extended(pdata->proto_date, pdata->protocol, NULL, &pdate)) { pdata_gdate = NULL; if (pdate && strlen(pdate) >= 6) { @@ -640,7 +640,7 @@ static void remmina_profiles_get_data(RemminaFile *remminafile, gpointer user_da g_debug("All dates are NULL, replacing date in the hashtable"); g_hash_table_replace(pdata->proto_date, g_strdup(pdata->protocol), NULL); } - }else { + } else { /** If there is not the protocol in the hash, we add it */ /** If the date in the profile is not NULL we use it */ if (pdata->pdatestr) { |