info: Use g_auto for variables

https://bugzilla.gnome.org/show_bug.cgi?id=788158
This commit is contained in:
Robert Ancell 2017-09-25 16:52:58 -04:00 committed by Georges Basile Stavracas Neto
parent a2b20a65cb
commit 1e62c99f41
6 changed files with 121 additions and 211 deletions

View file

@ -77,8 +77,8 @@ static void
default_app_changed (GtkAppChooserButton *button, default_app_changed (GtkAppChooserButton *button,
CcInfoDefaultAppsPanel *self) CcInfoDefaultAppsPanel *self)
{ {
GAppInfo *info; g_autoptr(GAppInfo) info = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
DefaultAppData *app_data; DefaultAppData *app_data;
int i; int i;
@ -89,8 +89,6 @@ default_app_changed (GtkAppChooserButton *button,
{ {
g_warning ("Failed to set '%s' as the default application for '%s': %s", g_warning ("Failed to set '%s' as the default application for '%s': %s",
g_app_info_get_name (info), app_data->content_type, error->message); g_app_info_get_name (info), app_data->content_type, error->message);
g_error_free (error);
error = NULL;
} }
else else
{ {
@ -101,22 +99,23 @@ default_app_changed (GtkAppChooserButton *button,
if (app_data->extra_type_filter) if (app_data->extra_type_filter)
{ {
const char *const *mime_types; const char *const *mime_types;
GPatternSpec *pattern; g_autoptr(GPatternSpec) pattern = NULL;
pattern = g_pattern_spec_new (app_data->extra_type_filter); pattern = g_pattern_spec_new (app_data->extra_type_filter);
mime_types = g_app_info_get_supported_types (info); mime_types = g_app_info_get_supported_types (info);
for (i = 0; mime_types && mime_types[i]; i++) for (i = 0; mime_types && mime_types[i]; i++)
{ {
g_autoptr(GError) local_error = NULL;
if (!g_pattern_match_string (pattern, mime_types[i])) if (!g_pattern_match_string (pattern, mime_types[i]))
continue; continue;
if (g_app_info_set_as_default_for_type (info, mime_types[i], &error) == FALSE) if (g_app_info_set_as_default_for_type (info, mime_types[i], &local_error) == FALSE)
{ {
g_warning ("Failed to set '%s' as the default application for secondary " g_warning ("Failed to set '%s' as the default application for secondary "
"content type '%s': %s", "content type '%s': %s",
g_app_info_get_name (info), mime_types[i], error->message); g_app_info_get_name (info), mime_types[i], local_error->message);
g_error_free (error);
} }
else else
{ {
@ -124,11 +123,7 @@ default_app_changed (GtkAppChooserButton *button,
g_app_info_get_name (info), mime_types[i]); g_app_info_get_name (info), mime_types[i]);
} }
} }
g_pattern_spec_free (pattern);
} }
g_object_unref (info);
} }
#define OFFSET(x) (G_STRUCT_OFFSET (CcInfoDefaultAppsPanel, x)) #define OFFSET(x) (G_STRUCT_OFFSET (CcInfoDefaultAppsPanel, x))

View file

@ -108,6 +108,18 @@ typedef struct
char **current; char **current;
} VersionData; } VersionData;
static void
version_data_free (VersionData *data)
{
g_free (data->major);
g_free (data->minor);
g_free (data->micro);
g_free (data->distributor);
g_free (data->date);
g_free (data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (VersionData, version_data_free);
G_DEFINE_TYPE_WITH_PRIVATE (CcInfoOverviewPanel, cc_info_overview_panel, CC_TYPE_PANEL) G_DEFINE_TYPE_WITH_PRIVATE (CcInfoOverviewPanel, cc_info_overview_panel, CC_TYPE_PANEL)
@ -153,7 +165,13 @@ version_text_handler (GMarkupParseContext *ctx,
{ {
VersionData *data = user_data; VersionData *data = user_data;
if (data->current != NULL) if (data->current != NULL)
*data->current = g_strstrip (g_strdup (text)); {
g_autofree char *stripped = NULL;
stripped = g_strstrip (g_strdup (text));
g_free (*data->current);
*data->current = g_strdup (stripped);
}
} }
static gboolean static gboolean
@ -168,16 +186,12 @@ load_gnome_version (char **version,
NULL, NULL,
NULL, NULL,
}; };
GError *error; g_autoptr(GError) error = NULL;
GMarkupParseContext *ctx; g_autoptr(GMarkupParseContext) ctx = NULL;
char *contents; g_autofree char *contents = NULL;
gsize length; gsize length;
VersionData *data; g_autoptr(VersionData) data = NULL;
gboolean ret;
ret = FALSE;
error = NULL;
if (!g_file_get_contents (DATADIR "/gnome/gnome-version.xml", if (!g_file_get_contents (DATADIR "/gnome/gnome-version.xml",
&contents, &contents,
&length, &length,
@ -200,19 +214,10 @@ load_gnome_version (char **version,
if (date != NULL) if (date != NULL)
*date = g_strdup (data->date); *date = g_strdup (data->date);
ret = TRUE; return TRUE;
} }
g_markup_parse_context_free (ctx); return FALSE;
g_free (data->major);
g_free (data->minor);
g_free (data->micro);
g_free (data->distributor);
g_free (data->date);
g_free (data);
g_free (contents);
return ret;
}; };
static void static void
@ -225,10 +230,10 @@ graphics_data_free (GraphicsData *gdata)
static char * static char *
get_renderer_from_session (void) get_renderer_from_session (void)
{ {
GDBusProxy *session_proxy; g_autoptr(GDBusProxy) session_proxy = NULL;
GVariant *renderer_variant; g_autoptr(GVariant) renderer_variant = NULL;
char *renderer; char *renderer;
GError *error = NULL; g_autoptr(GError) error = NULL;
session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE, G_DBUS_PROXY_FLAGS_NONE,
@ -241,12 +246,10 @@ get_renderer_from_session (void)
{ {
g_warning ("Unable to connect to create a proxy for org.gnome.SessionManager: %s", g_warning ("Unable to connect to create a proxy for org.gnome.SessionManager: %s",
error->message); error->message);
g_error_free (error);
return NULL; return NULL;
} }
renderer_variant = g_dbus_proxy_get_cached_property (session_proxy, "Renderer"); renderer_variant = g_dbus_proxy_get_cached_property (session_proxy, "Renderer");
g_object_unref (session_proxy);
if (!renderer_variant) if (!renderer_variant)
{ {
@ -255,7 +258,6 @@ get_renderer_from_session (void)
} }
renderer = info_cleanup (g_variant_get_string (renderer_variant, NULL)); renderer = info_cleanup (g_variant_get_string (renderer_variant, NULL));
g_variant_unref (renderer_variant);
return renderer; return renderer;
} }
@ -265,10 +267,9 @@ get_renderer_from_helper (gboolean discrete_gpu)
{ {
int status; int status;
char *argv[] = { GNOME_SESSION_DIR "/gnome-session-check-accelerated", NULL }; char *argv[] = { GNOME_SESSION_DIR "/gnome-session-check-accelerated", NULL };
char **envp = NULL; g_auto(GStrv) envp = NULL;
char *renderer = NULL; g_autofree char *renderer = NULL;
char *ret = NULL; g_autoptr(GError) error = NULL;
GError *error = NULL;
if (discrete_gpu) if (discrete_gpu)
{ {
@ -281,31 +282,25 @@ get_renderer_from_helper (gboolean discrete_gpu)
g_debug ("Failed to get %s GPU: %s", g_debug ("Failed to get %s GPU: %s",
discrete_gpu ? "discrete" : "integrated", discrete_gpu ? "discrete" : "integrated",
error->message); error->message);
g_error_free (error); return NULL;
goto out;
} }
if (!g_spawn_check_exit_status (status, NULL)) if (!g_spawn_check_exit_status (status, NULL))
goto out; return NULL;
if (renderer == NULL || *renderer == '\0') if (renderer == NULL || *renderer == '\0')
goto out; return NULL;
ret = info_cleanup (renderer); return info_cleanup (renderer);
out:
g_free (renderer);
g_strfreev (envp);
return ret;
} }
static gboolean static gboolean
has_dual_gpu (void) has_dual_gpu (void)
{ {
GDBusProxy *switcheroo_proxy; g_autoptr(GDBusProxy) switcheroo_proxy = NULL;
GVariant *dualgpu_variant; g_autoptr(GVariant) dualgpu_variant = NULL;
gboolean ret; gboolean ret;
GError *error = NULL; g_autoptr(GError) error = NULL;
switcheroo_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, switcheroo_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE, G_DBUS_PROXY_FLAGS_NONE,
@ -318,12 +313,10 @@ has_dual_gpu (void)
{ {
g_debug ("Unable to connect to create a proxy for net.hadess.SwitcherooControl: %s", g_debug ("Unable to connect to create a proxy for net.hadess.SwitcherooControl: %s",
error->message); error->message);
g_error_free (error);
return FALSE; return FALSE;
} }
dualgpu_variant = g_dbus_proxy_get_cached_property (switcheroo_proxy, "HasDualGpu"); dualgpu_variant = g_dbus_proxy_get_cached_property (switcheroo_proxy, "HasDualGpu");
g_object_unref (switcheroo_proxy);
if (!dualgpu_variant) if (!dualgpu_variant)
{ {
@ -332,7 +325,6 @@ has_dual_gpu (void)
} }
ret = g_variant_get_boolean (dualgpu_variant); ret = g_variant_get_boolean (dualgpu_variant);
g_variant_unref (dualgpu_variant);
if (ret) if (ret)
g_debug ("Dual-GPU machine detected"); g_debug ("Dual-GPU machine detected");
@ -361,8 +353,8 @@ get_graphics_data (void)
if (x11_or_wayland) if (x11_or_wayland)
{ {
char *discrete_renderer = NULL; g_autofree char *discrete_renderer = NULL;
char *renderer; g_autofree char *renderer = NULL;
renderer = get_renderer_from_session (); renderer = get_renderer_from_session ();
if (!renderer) if (!renderer)
@ -375,8 +367,6 @@ get_graphics_data (void)
result->hardware_string = g_strdup_printf ("%s / %s", result->hardware_string = g_strdup_printf ("%s / %s",
renderer, renderer,
discrete_renderer); discrete_renderer);
g_free (renderer);
g_free (discrete_renderer);
} }
#endif #endif
@ -390,32 +380,31 @@ static GHashTable*
get_os_info (void) get_os_info (void)
{ {
GHashTable *hashtable; GHashTable *hashtable;
gchar *buffer; g_autofree gchar *buffer = NULL;
hashtable = NULL; hashtable = NULL;
if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL)) if (g_file_get_contents ("/etc/os-release", &buffer, NULL, NULL))
{ {
gchar **lines; g_auto(GStrv) lines = NULL;
gint i; gint i;
lines = g_strsplit (buffer, "\n", -1); lines = g_strsplit (buffer, "\n", -1);
for (i = 0; lines[i] != NULL; i++) for (i = 0; lines[i] != NULL; i++)
{ {
gchar *delimiter, *key, *value; gchar *delimiter;
/* Initialize the hash table if needed */ /* Initialize the hash table if needed */
if (!hashtable) if (!hashtable)
hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
delimiter = strstr (lines[i], "="); delimiter = strstr (lines[i], "=");
value = NULL;
key = NULL;
if (delimiter != NULL) if (delimiter != NULL)
{ {
gint size; gint size;
gchar *key, *value;
key = g_strndup (lines[i], delimiter - lines[i]); key = g_strndup (lines[i], delimiter - lines[i]);
@ -437,9 +426,6 @@ get_os_info (void)
g_hash_table_insert (hashtable, key, value); g_hash_table_insert (hashtable, key, value);
} }
} }
g_strfreev (lines);
g_free (buffer);
} }
return hashtable; return hashtable;
@ -505,30 +491,24 @@ query_done (GFile *file,
CcInfoOverviewPanel *self) CcInfoOverviewPanel *self)
{ {
CcInfoOverviewPanelPrivate *priv; CcInfoOverviewPanelPrivate *priv;
GFileInfo *info; g_autoptr(GFileInfo) info = NULL;
GError *error = NULL; g_autoptr(GError) error = NULL;
info = g_file_query_filesystem_info_finish (file, res, &error); info = g_file_query_filesystem_info_finish (file, res, &error);
if (info != NULL) if (info != NULL)
{ {
priv = cc_info_overview_panel_get_instance_private (self); priv = cc_info_overview_panel_get_instance_private (self);
priv->total_bytes += g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); priv->total_bytes += g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
g_object_unref (info);
} }
else else
{ {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
g_error_free (error);
return; return;
}
else else
{ {
char *path; g_autofree char *path = NULL;
path = g_file_get_path (file); path = g_file_get_path (file);
g_warning ("Failed to get filesystem free space for '%s': %s", path, error->message); g_warning ("Failed to get filesystem free space for '%s': %s", path, error->message);
g_free (path);
g_error_free (error);
} }
} }
@ -540,16 +520,15 @@ static void
get_primary_disc_info_start (CcInfoOverviewPanel *self) get_primary_disc_info_start (CcInfoOverviewPanel *self)
{ {
GUnixMountEntry *mount; GUnixMountEntry *mount;
GFile *file; g_autoptr(GFile) file = NULL;
CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self); CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
if (priv->primary_mounts == NULL) if (priv->primary_mounts == NULL)
{ {
char *size; g_autofree char *size = NULL;
size = g_format_size (priv->total_bytes); size = g_format_size (priv->total_bytes);
gtk_label_set_text (GTK_LABEL (priv->disk_label), size); gtk_label_set_text (GTK_LABEL (priv->disk_label), size);
g_free (size);
return; return;
} }
@ -565,7 +544,6 @@ get_primary_disc_info_start (CcInfoOverviewPanel *self)
priv->cancellable, priv->cancellable,
(GAsyncReadyCallback) query_done, (GAsyncReadyCallback) query_done,
self); self);
g_object_unref (file);
} }
static void static void
@ -618,9 +596,8 @@ get_primary_disc_info (CcInfoOverviewPanel *self)
static char * static char *
get_cpu_info (const glibtop_sysinfo *info) get_cpu_info (const glibtop_sysinfo *info)
{ {
GHashTable *counts; g_autoptr(GHashTable) counts = NULL;
GString *cpu; g_autoptr(GString) cpu = NULL;
char *ret;
GHashTableIter iter; GHashTableIter iter;
gpointer key, value; gpointer key, value;
int i; int i;
@ -657,7 +634,7 @@ get_cpu_info (const glibtop_sysinfo *info)
g_hash_table_iter_init (&iter, counts); g_hash_table_iter_init (&iter, counts);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
{ {
char *cleanedup; g_autofree char *cleanedup = NULL;
int count; int count;
count = GPOINTER_TO_INT (value); count = GPOINTER_TO_INT (value);
@ -666,14 +643,9 @@ get_cpu_info (const glibtop_sysinfo *info)
g_string_append_printf (cpu, "%s \303\227 %d ", cleanedup, count); g_string_append_printf (cpu, "%s \303\227 %d ", cleanedup, count);
else else
g_string_append_printf (cpu, "%s ", cleanedup); g_string_append_printf (cpu, "%s ", cleanedup);
g_free (cleanedup);
} }
g_hash_table_destroy (counts); return g_strdup (cpu->str);
ret = g_string_free (cpu, FALSE);
return ret;
} }
static void static void
@ -743,13 +715,10 @@ set_virtualization_label (CcInfoOverviewPanel *self,
static void static void
info_overview_panel_setup_virt (CcInfoOverviewPanel *self) info_overview_panel_setup_virt (CcInfoOverviewPanel *self)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
GDBusProxy *systemd_proxy; g_autoptr(GDBusProxy) systemd_proxy = NULL;
GVariant *variant; g_autoptr(GVariant) variant = NULL;
GVariant *inner; GVariant *inner;
char *str;
str = NULL;
systemd_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, systemd_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE, G_DBUS_PROXY_FLAGS_NONE,
@ -763,8 +732,8 @@ info_overview_panel_setup_virt (CcInfoOverviewPanel *self)
if (systemd_proxy == NULL) if (systemd_proxy == NULL)
{ {
g_debug ("systemd not available, bailing: %s", error->message); g_debug ("systemd not available, bailing: %s", error->message);
g_error_free (error); set_virtualization_label (self, NULL);
goto bail; return;
} }
variant = g_dbus_proxy_call_sync (systemd_proxy, variant = g_dbus_proxy_call_sync (systemd_proxy,
@ -777,20 +746,12 @@ info_overview_panel_setup_virt (CcInfoOverviewPanel *self)
if (variant == NULL) if (variant == NULL)
{ {
g_debug ("Failed to get property '%s': %s", "Virtualization", error->message); g_debug ("Failed to get property '%s': %s", "Virtualization", error->message);
g_error_free (error); set_virtualization_label (self, NULL);
g_object_unref (systemd_proxy); return;
goto bail;
} }
g_variant_get (variant, "(v)", &inner); g_variant_get (variant, "(v)", &inner);
str = g_variant_dup_string (inner, NULL); set_virtualization_label (self, g_variant_get_string (inner, NULL));
g_variant_unref (variant);
g_object_unref (systemd_proxy);
bail:
set_virtualization_label (self, str);
g_free (str);
} }
static void static void
@ -799,7 +760,10 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
gboolean res; gboolean res;
glibtop_mem mem; glibtop_mem mem;
const glibtop_sysinfo *info; const glibtop_sysinfo *info;
char *text; g_autofree char *memory_text = NULL;
g_autofree char *cpu_text = NULL;
g_autofree char *os_type_text = NULL;
g_autofree char *os_name_text = NULL;
CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self); CcInfoOverviewPanelPrivate *priv = cc_info_overview_panel_get_instance_private (self);
res = load_gnome_version (&priv->gnome_version, res = load_gnome_version (&priv->gnome_version,
@ -807,29 +771,25 @@ info_overview_panel_setup_overview (CcInfoOverviewPanel *self)
&priv->gnome_date); &priv->gnome_date);
if (res) if (res)
{ {
g_autofree gchar *text = NULL;
text = g_strdup_printf (_("Version %s"), priv->gnome_version); text = g_strdup_printf (_("Version %s"), priv->gnome_version);
gtk_label_set_text (GTK_LABEL (priv->version_label), text); gtk_label_set_text (GTK_LABEL (priv->version_label), text);
g_free (text);
} }
glibtop_get_mem (&mem); glibtop_get_mem (&mem);
text = g_format_size_full (mem.total, G_FORMAT_SIZE_IEC_UNITS); memory_text = g_format_size_full (mem.total, G_FORMAT_SIZE_IEC_UNITS);
gtk_label_set_text (GTK_LABEL (priv->memory_label), text ? text : ""); gtk_label_set_text (GTK_LABEL (priv->memory_label), memory_text ? memory_text : "");
g_free (text);
info = glibtop_get_sysinfo (); info = glibtop_get_sysinfo ();
text = get_cpu_info (info); cpu_text = get_cpu_info (info);
gtk_label_set_markup (GTK_LABEL (priv->processor_label), text ? text : ""); gtk_label_set_markup (GTK_LABEL (priv->processor_label), cpu_text ? cpu_text : "");
g_free (text);
text = get_os_type (); os_type_text = get_os_type ();
gtk_label_set_text (GTK_LABEL (priv->os_type_label), text ? text : ""); gtk_label_set_text (GTK_LABEL (priv->os_type_label), os_type_text ? os_type_text : "");
g_free (text);
text = get_os_name (); os_name_text = get_os_name ();
gtk_label_set_text (GTK_LABEL (priv->os_name_label), text ? text : ""); gtk_label_set_text (GTK_LABEL (priv->os_name_label), os_name_text ? os_name_text : "");
g_free (text);
get_primary_disc_info (self); get_primary_disc_info (self);
@ -852,9 +812,9 @@ static void
on_updates_button_clicked (GtkWidget *widget, on_updates_button_clicked (GtkWidget *widget,
CcInfoOverviewPanel *self) CcInfoOverviewPanel *self)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
gboolean ret; gboolean ret;
gchar **argv; g_auto(GStrv) argv = NULL;
argv = g_new0 (gchar *, 3); argv = g_new0 (gchar *, 3);
if (does_gnome_software_exist ()) if (does_gnome_software_exist ())
@ -868,11 +828,7 @@ on_updates_button_clicked (GtkWidget *widget,
} }
ret = g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error); ret = g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error);
if (!ret) if (!ret)
{
g_warning ("Failed to spawn %s: %s", argv[0], error->message); g_warning ("Failed to spawn %s: %s", argv[0], error->message);
g_error_free (error);
}
g_strfreev (argv);
} }
static void static void

View file

@ -155,9 +155,9 @@ autorun_get_preferences (CcInfoRemovableMediaPanel *self,
gboolean *pref_ignore, gboolean *pref_ignore,
gboolean *pref_open_folder) gboolean *pref_open_folder)
{ {
char **x_content_start_app; g_auto(GStrv) x_content_start_app = NULL;
char **x_content_ignore; g_auto(GStrv) x_content_ignore = NULL;
char **x_content_open_folder; g_auto(GStrv) x_content_open_folder = NULL;
g_return_if_fail (pref_start_app != NULL); g_return_if_fail (pref_start_app != NULL);
g_return_if_fail (pref_ignore != NULL); g_return_if_fail (pref_ignore != NULL);
@ -181,9 +181,6 @@ autorun_get_preferences (CcInfoRemovableMediaPanel *self,
if (x_content_open_folder != NULL) { if (x_content_open_folder != NULL) {
*pref_open_folder = media_panel_g_strv_find (x_content_open_folder, x_content_type) != -1; *pref_open_folder = media_panel_g_strv_find (x_content_open_folder, x_content_type) != -1;
} }
g_strfreev (x_content_ignore);
g_strfreev (x_content_start_app);
g_strfreev (x_content_open_folder);
} }
static void static void
@ -193,9 +190,9 @@ autorun_set_preferences (CcInfoRemovableMediaPanel *self,
gboolean pref_ignore, gboolean pref_ignore,
gboolean pref_open_folder) gboolean pref_open_folder)
{ {
char **x_content_start_app; g_auto(GStrv) x_content_start_app = NULL;
char **x_content_ignore; g_auto(GStrv) x_content_ignore = NULL;
char **x_content_open_folder; g_auto(GStrv) x_content_open_folder = NULL;
g_assert (x_content_type != NULL); g_assert (x_content_type != NULL);
@ -227,10 +224,6 @@ autorun_set_preferences (CcInfoRemovableMediaPanel *self,
g_settings_set_strv (self->media_settings, g_settings_set_strv (self->media_settings,
PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder); PREF_MEDIA_AUTORUN_X_CONTENT_OPEN_FOLDER, (const gchar * const*) x_content_open_folder);
g_strfreev (x_content_open_folder);
g_strfreev (x_content_ignore);
g_strfreev (x_content_start_app);
} }
static void static void
@ -239,7 +232,7 @@ custom_item_activated_cb (GtkAppChooserButton *button,
gpointer user_data) gpointer user_data)
{ {
CcInfoRemovableMediaPanel *self = user_data; CcInfoRemovableMediaPanel *self = user_data;
gchar *content_type; g_autofree gchar *content_type = NULL;
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button)); content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (button));
@ -253,8 +246,6 @@ custom_item_activated_cb (GtkAppChooserButton *button,
autorun_set_preferences (self, content_type, autorun_set_preferences (self, content_type,
FALSE, TRUE, FALSE); FALSE, TRUE, FALSE);
} }
g_free (content_type);
} }
static void static void
@ -262,8 +253,8 @@ combo_box_changed_cb (GtkComboBox *combo_box,
gpointer user_data) gpointer user_data)
{ {
CcInfoRemovableMediaPanel *self = user_data; CcInfoRemovableMediaPanel *self = user_data;
GAppInfo *info; g_autoptr(GAppInfo) info = NULL;
gchar *content_type; g_autofree gchar *content_type = NULL;
info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box)); info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (combo_box));
@ -274,9 +265,6 @@ combo_box_changed_cb (GtkComboBox *combo_box,
autorun_set_preferences (self, content_type, autorun_set_preferences (self, content_type,
TRUE, FALSE, FALSE); TRUE, FALSE, FALSE);
g_app_info_set_as_default_for_type (info, content_type, NULL); g_app_info_set_as_default_for_type (info, content_type, NULL);
g_object_unref (info);
g_free (content_type);
} }
static void static void
@ -289,8 +277,8 @@ prepare_combo_box (CcInfoRemovableMediaPanel *self,
gboolean pref_start_app; gboolean pref_start_app;
gboolean pref_ignore; gboolean pref_ignore;
gboolean pref_open_folder; gboolean pref_open_folder;
GAppInfo *info; g_autoptr(GAppInfo) info = NULL;
gchar *content_type; g_autofree gchar *content_type = NULL;
content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser)); content_type = gtk_app_chooser_get_content_type (GTK_APP_CHOOSER (app_chooser));
@ -304,7 +292,6 @@ prepare_combo_box (CcInfoRemovableMediaPanel *self,
/* append the separator only if we have >= 1 apps in the chooser */ /* append the separator only if we have >= 1 apps in the chooser */
if (info != NULL) { if (info != NULL) {
gtk_app_chooser_button_append_separator (app_chooser); gtk_app_chooser_button_append_separator (app_chooser);
g_object_unref (info);
} }
gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK, gtk_app_chooser_button_append_custom_item (app_chooser, CUSTOM_ITEM_ASK,
@ -336,8 +323,6 @@ prepare_combo_box (CcInfoRemovableMediaPanel *self,
G_CALLBACK (combo_box_changed_cb), self); G_CALLBACK (combo_box_changed_cb), self);
g_signal_connect (app_chooser, "custom-item-activated", g_signal_connect (app_chooser, "custom-item-activated",
G_CALLBACK (custom_item_activated_cb), self); G_CALLBACK (custom_item_activated_cb), self);
g_free (content_type);
} }
static void static void
@ -346,12 +331,10 @@ other_type_combo_box_changed (GtkComboBox *combo_box,
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
char *x_content_type; g_autofree gchar *x_content_type = NULL;
GtkWidget *action_container; GtkWidget *action_container;
GtkWidget *action_label; GtkWidget *action_label;
x_content_type = NULL;
if (!gtk_combo_box_get_active_iter (combo_box, &iter)) { if (!gtk_combo_box_get_active_iter (combo_box, &iter)) {
return; return;
} }
@ -379,8 +362,6 @@ other_type_combo_box_changed (GtkComboBox *combo_box,
action_label = self->media_other_action_label; action_label = self->media_other_action_label;
gtk_label_set_mnemonic_widget (GTK_LABEL (action_label), self->other_application_combo); gtk_label_set_mnemonic_widget (GTK_LABEL (action_label), self->other_application_combo);
g_free (x_content_type);
} }
static void static void
@ -490,7 +471,7 @@ info_panel_setup_media (CcInfoRemovableMediaPanel *self)
for (l = content_types; l != NULL; l = l->next) { for (l = content_types; l != NULL; l = l->next) {
char *content_type = l->data; char *content_type = l->data;
char *description = NULL; g_autofree char *description = NULL;
if (!g_str_has_prefix (content_type, "x-content/")) if (!g_str_has_prefix (content_type, "x-content/"))
continue; continue;
@ -524,7 +505,6 @@ info_panel_setup_media (CcInfoRemovableMediaPanel *self)
0, description, 0, description,
1, content_type, 1, content_type,
-1); -1);
g_free (description);
skip: skip:
; ;
} }

View file

@ -121,17 +121,15 @@ gboolean
gsd_is_removable_mount (GUnixMountEntry *mount) gsd_is_removable_mount (GUnixMountEntry *mount)
{ {
const char *mount_path; const char *mount_path;
char *path; g_autofree gchar *path = NULL;
mount_path = g_unix_mount_get_mount_path (mount); mount_path = g_unix_mount_get_mount_path (mount);
if (mount_path == NULL) if (mount_path == NULL)
return FALSE; return FALSE;
path = g_strdup_printf ("/run/media/%s", g_get_user_name ()); path = g_strdup_printf ("/run/media/%s", g_get_user_name ());
if (g_str_has_prefix (mount_path, path)) { if (g_str_has_prefix (mount_path, path))
g_free (path);
return TRUE; return TRUE;
}
g_free (path);
return FALSE; return FALSE;
} }

View file

@ -32,7 +32,8 @@ typedef struct
static char * static char *
prettify_info (const char *info) prettify_info (const char *info)
{ {
char *pretty; g_autofree char *escaped = NULL;
g_autofree gchar *pretty = NULL;
int i; int i;
static const ReplaceStrings rs[] = { static const ReplaceStrings rs[] = {
{ "Mesa DRI ", ""}, { "Mesa DRI ", ""},
@ -49,22 +50,19 @@ prettify_info (const char *info)
if (*info == '\0') if (*info == '\0')
return NULL; return NULL;
pretty = g_markup_escape_text (info, -1); escaped = g_markup_escape_text (info, -1);
pretty = g_strchug (g_strchomp (pretty)); pretty = g_strdup (g_strstrip (escaped));
for (i = 0; i < G_N_ELEMENTS (rs); i++) for (i = 0; i < G_N_ELEMENTS (rs); i++)
{ {
GError *error; g_autoptr(GError) error = NULL;
GRegex *re; g_autoptr(GRegex) re = NULL;
char *new; g_autofree gchar *new = NULL;
error = NULL;
re = g_regex_new (rs[i].regex, 0, 0, &error); re = g_regex_new (rs[i].regex, 0, 0, &error);
if (re == NULL) if (re == NULL)
{ {
g_warning ("Error building regex: %s", error->message); g_warning ("Error building regex: %s", error->message);
g_error_free (error);
continue; continue;
} }
@ -76,38 +74,33 @@ prettify_info (const char *info)
0, 0,
&error); &error);
g_regex_unref (re);
if (error != NULL) if (error != NULL)
{ {
g_warning ("Error replacing %s: %s", rs[i].regex, error->message); g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
g_error_free (error);
continue; continue;
} }
g_free (pretty); g_free (pretty);
pretty = new; pretty = g_steal_pointer (&new);
} }
return pretty; return g_steal_pointer (&pretty);
} }
static char * static char *
remove_duplicate_whitespace (const char *old) remove_duplicate_whitespace (const char *old)
{ {
char *new; g_autofree gchar *new = NULL;
GRegex *re; g_autoptr(GRegex) re = NULL;
GError *error; g_autoptr(GError) error = NULL;
if (old == NULL) if (old == NULL)
return NULL; return NULL;
error = NULL;
re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error); re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
if (re == NULL) if (re == NULL)
{ {
g_warning ("Error building regex: %s", error->message); g_warning ("Error building regex: %s", error->message);
g_error_free (error);
return g_strdup (old); return g_strdup (old);
} }
new = g_regex_replace (re, new = g_regex_replace (re,
@ -117,25 +110,20 @@ remove_duplicate_whitespace (const char *old)
" ", " ",
0, 0,
&error); &error);
g_regex_unref (re);
if (new == NULL) if (new == NULL)
{ {
g_warning ("Error replacing string: %s", error->message); g_warning ("Error replacing string: %s", error->message);
g_error_free (error);
return g_strdup (old); return g_strdup (old);
} }
return new; return g_steal_pointer (&new);
} }
char * char *
info_cleanup (const char *input) info_cleanup (const char *input)
{ {
char *pretty, *ret; g_autofree char *pretty;
pretty = prettify_info (input); pretty = prettify_info (input);
ret = remove_duplicate_whitespace (pretty); return remove_duplicate_whitespace (pretty);
g_free (pretty);
return ret;
} }

View file

@ -27,10 +27,9 @@
static void static void
test_info (void) test_info (void)
{ {
char *contents; g_autofree gchar *contents = NULL;
char *result;
guint i; guint i;
char **lines; g_auto(GStrv) lines = NULL;
if (g_file_get_contents (TEST_SRCDIR "/info-cleanup-test.txt", &contents, NULL, NULL) == FALSE) { if (g_file_get_contents (TEST_SRCDIR "/info-cleanup-test.txt", &contents, NULL, NULL) == FALSE) {
g_warning ("Failed to load '%s'", TEST_SRCDIR "/info-cleanup-test.txt"); g_warning ("Failed to load '%s'", TEST_SRCDIR "/info-cleanup-test.txt");
@ -46,8 +45,9 @@ test_info (void)
} }
for (i = 0; lines[i] != NULL; i++) { for (i = 0; lines[i] != NULL; i++) {
char *utf8; g_auto(GStrv) items = NULL;
char **items; g_autofree gchar *utf8 = NULL;
g_autofree gchar *result = NULL;
if (*lines[i] == '#') if (*lines[i] == '#')
continue; continue;
@ -65,14 +65,7 @@ test_info (void)
g_debug ("Result for '%s' matches '%s'", g_debug ("Result for '%s' matches '%s'",
utf8, result); utf8, result);
} }
g_free (result);
g_free (utf8);
g_strfreev (items);
} }
g_strfreev (lines);
g_free (contents);
} }
int main (int argc, char **argv) int main (int argc, char **argv)