[epiphany/mcatanzaro/#1352: 2/2] prefs-appearance-page: Don't leak URIs




commit f4299f6301413ab1fae07ded2df899d19a3707e2
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Sep 26 09:28:41 2020 -0500

    prefs-appearance-page: Don't leak URIs
    
    Also, convert surrounding code to use autoptrs

 src/preferences/prefs-appearance-page.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/src/preferences/prefs-appearance-page.c b/src/preferences/prefs-appearance-page.c
index 9af61f0bb..c315918b9 100644
--- a/src/preferences/prefs-appearance-page.c
+++ b/src/preferences/prefs-appearance-page.c
@@ -152,25 +152,22 @@ css_file_created_cb (GObject      *source,
                      GAsyncResult *result,
                      gpointer      user_data)
 {
-  GFile *file = G_FILE (source);
-  GFileOutputStream *stream;
-  GError *error = NULL;
+  g_autoptr (GFile) = G_FILE (source);
+  g_autpotr (GFileOutputStream) stream = NULL;
+  g_autoptr (GError) error = NULL;
+  g_autofree char *uri = NULL;
 
   stream = g_file_create_finish (file, result, &error);
   if (stream == NULL && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
     g_warning ("Failed to create %s: %s", g_file_get_path (file), error->message);
   else {
-    if (ephy_is_running_inside_flatpak ())
-      ephy_open_uri_via_flatpak_portal (g_file_get_uri (file));
-    else
+    if (ephy_is_running_inside_flatpak ()) {
+      uri = g_file_get_uri (file);
+      ephy_open_uri_via_flatpak_portal (uri);
+    } else {
       ephy_file_launch_handler (file, gtk_get_current_event_time ());
+    }
   }
-
-  if (error != NULL)
-    g_error_free (error);
-  if (stream != NULL)
-    g_object_unref (stream);
-  g_object_unref (file);
 }
 
 static void
@@ -194,15 +191,18 @@ js_file_created_cb (GObject      *source,
   g_autoptr (GFile) file = G_FILE (source);
   g_autoptr (GFileOutputStream) stream = NULL;
   g_autoptr (GError) error = NULL;
+  g_autofree char *uri = NULL;
 
   stream = g_file_create_finish (file, result, &error);
   if (stream == NULL && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
     g_warning ("Failed to create %s: %s", g_file_get_path (file), error->message);
   else {
-    if (ephy_is_running_inside_flatpak ())
-      ephy_open_uri_via_flatpak_portal (g_file_get_uri (file));
-    else
+    if (ephy_is_running_inside_flatpak ()) {
+      uri = g_file_get_uri (file);
+      ephy_open_uri_via_flatpak_portal (uri);
+    } else {
       ephy_file_launch_handler (file, gtk_get_current_event_time ());
+    }
   }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]