[sound-juicer/wip/hadess/fix-prefs-warning: 7/7] main: Fix warning when opening preferences




commit 42927ec247647e136cbbe0a26a0c3e5b96145b19
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Feb 11 18:19:36 2021 +0100

    main: Fix warning when opening preferences
    
    If brasero_medium_monitor_get_drive() fails to return a drive, we would
    get a warning when opening the preferences. This can happen on a system
    where the optical drive is removable, such as an external USB drive.
    
     #0  0x00007ffff7edcb32 in g_logv () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
     #1  0x00007ffff7edcda3 in g_log () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
     #2  0x0000555555575b3d in device_changed_cb (settings=<optimized out>, key=<optimized out>, 
user_data=<optimized out>) at ../src/sj-prefs.c:293
     #3  0x000055555557641c in show_preferences_dialog () at ../src/sj-prefs.c:446

 src/sj-prefs.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
---
diff --git a/src/sj-prefs.c b/src/sj-prefs.c
index b645278c..2a7233af 100644
--- a/src/sj-prefs.c
+++ b/src/sj-prefs.c
@@ -286,18 +286,17 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(BraseroDrive, g_object_unref)
  */
 static void device_changed_cb (GSettings *settings, const gchar *key, gpointer user_data)
 {
-  BraseroDrive *drive;
-  BraseroMediumMonitor *monitor;
-  char *value;
+  g_autoptr(BraseroMediumMonitor) monitor = NULL;
+  g_autofree char *value = NULL;
 
   g_return_if_fail (strcmp (key, SJ_SETTINGS_DEVICE) == 0);
 
   monitor = brasero_medium_monitor_get_default ();
   value = g_settings_get_string (settings, key);
   if ((value != NULL) && (*value != '\0')) {
+    g_autoptr(BraseroDrive) drive = NULL;
     drive = brasero_medium_monitor_get_drive (monitor, value);
     brasero_drive_selection_set_active (BRASERO_DRIVE_SELECTION (cd_option), drive);
-    g_object_unref (drive);
   } else {
     GSList *drives;
     drives = brasero_medium_monitor_get_drives (monitor, BRASERO_DRIVE_TYPE_ALL_BUT_FILE);
@@ -305,8 +304,6 @@ static void device_changed_cb (GSettings *settings, const gchar *key, gpointer u
       brasero_drive_selection_set_active (BRASERO_DRIVE_SELECTION (cd_option), drives->data);
     g_slist_free_full (drives, (GDestroyNotify) g_object_unref);
   }
-  g_free (value);
-  g_object_unref (monitor);
 }
 
 static void prefs_drive_changed (BraseroDriveSelection *selection, BraseroDrive *drive, gpointer user_data)


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