[Spice-devel] [PATCH spice-gtk 36/44] fixup! usb-redir: add implementation of emulated CD device

Frediano Ziglio fziglio at redhat.com
Tue Jul 30 12:03:23 UTC 2019


Use g_clear_object where possible
---
 src/usb-device-cd.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/src/usb-device-cd.c b/src/usb-device-cd.c
index 9554a82f..e48236b4 100644
--- a/src/usb-device-cd.c
+++ b/src/usb-device-cd.c
@@ -131,8 +131,7 @@ static int cd_device_open_stream(SpiceCdLU *unit, const char *filename)
         }
         if (!unit->stream) {
             SPICE_DEBUG("%s: can't open stream on %s", __FUNCTION__, unit->filename);
-            g_object_unref(unit->file_object);
-            unit->file_object = NULL;
+            g_clear_object(&unit->file_object);
             error = -1;
         }
     }
@@ -286,8 +285,7 @@ static int cd_device_open_stream(SpiceCdLU *unit, const char *filename)
         }
         if (!unit->stream) {
             SPICE_DEBUG("%s: can't open stream on %s", __FUNCTION__, unit->filename);
-            g_object_unref(unit->file_object);
-            unit->file_object = NULL;
+            g_clear_object(&unit->file_object);
             error = -1;
         }
     } else {
@@ -353,14 +351,8 @@ static gboolean open_stream(SpiceCdLU *unit, const char *filename)
 
 static void close_stream(SpiceCdLU *unit)
 {
-    if (unit->stream) {
-        g_object_unref(unit->stream);
-        unit->stream = NULL;
-    }
-    if (unit->file_object) {
-        g_object_unref(unit->file_object);
-        unit->file_object = NULL;
-    }
+    g_clear_object(&unit->stream);
+    g_clear_object(&unit->file_object);
 }
 
 static gboolean load_lun(UsbCd *d, int unit, gboolean load)
-- 
2.20.1



More information about the Spice-devel mailing list