[Spice-commits] 6 commits - configure.ac src/bio-gio.c src/channel-display.c src/channel-display-mjpeg.c src/channel-main.c src/channel-playback.c src/channel-record.c src/channel-smartcard.c src/channel-usbredir.c src/decode-glz.c src/desktop-integration.c src/smartcard-manager.c src/spice-audio.c src/spice-channel.c src/spice-gstaudio.c src/spice-gtk-session.c src/spice-option.c src/spice-pulse.c src/spice-session.c src/spice-widget.c src/spice-widget-cairo.c src/usb-acl-helper.c src/usbutil.c src/wocky-http-proxy.c

Pavel Grunt pgrunt at kemper.freedesktop.org
Thu Apr 7 10:02:47 UTC 2016


 configure.ac                |   13 ++++++++++--
 src/bio-gio.c               |    3 --
 src/channel-display-mjpeg.c |    3 --
 src/channel-display.c       |   10 ++-------
 src/channel-main.c          |    6 +----
 src/channel-playback.c      |    3 --
 src/channel-record.c        |    9 ++------
 src/channel-smartcard.c     |   28 +++++---------------------
 src/channel-usbredir.c      |    9 ++------
 src/decode-glz.c            |    3 --
 src/desktop-integration.c   |    6 ++---
 src/smartcard-manager.c     |   13 ++----------
 src/spice-audio.c           |    5 ----
 src/spice-channel.c         |   37 +++++++----------------------------
 src/spice-gstaudio.c        |   32 ++++++++----------------------
 src/spice-gtk-session.c     |   12 ++++-------
 src/spice-option.c          |    3 --
 src/spice-pulse.c           |   46 ++++++++++++--------------------------------
 src/spice-session.c         |   24 +++++++++-------------
 src/spice-widget-cairo.c    |   11 ++--------
 src/spice-widget.c          |   44 ++++++++++--------------------------------
 src/usb-acl-helper.c        |   11 +---------
 src/usbutil.c               |    6 ++---
 src/wocky-http-proxy.c      |    6 +----
 24 files changed, 106 insertions(+), 237 deletions(-)

New commits:
commit 532f2f314de955780fedfd0cac1d37553d06d273
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Wed Apr 6 15:40:12 2016 +0200

    Use g_clear_pointer if possible
    
    Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

diff --git a/src/bio-gio.c b/src/bio-gio.c
index 108ac1a..b310c97 100644
--- a/src/bio-gio.c
+++ b/src/bio-gio.c
@@ -76,8 +76,7 @@ static int bio_gio_destroy(BIO *bio)
         return 0;
 
     SPICE_DEBUG("bio gsocket destroy");
-    g_free(bio->method);
-    bio->method = NULL;;
+    g_clear_pointer(&bio->method, g_free);
 
     return 1;
 }
diff --git a/src/channel-display-mjpeg.c b/src/channel-display-mjpeg.c
index 95d5b33..5ea3371 100644
--- a/src/channel-display-mjpeg.c
+++ b/src/channel-display-mjpeg.c
@@ -151,6 +151,5 @@ G_GNUC_INTERNAL
 void stream_mjpeg_cleanup(display_stream *st)
 {
     jpeg_destroy_decompress(&st->mjpeg_cinfo);
-    g_free(st->out_frame);
-    st->out_frame = NULL;
+    g_clear_pointer(&st->out_frame, g_free);
 }
diff --git a/src/channel-display.c b/src/channel-display.c
index 431c2e7..b6c79e0 100644
--- a/src/channel-display.c
+++ b/src/channel-display.c
@@ -831,11 +831,8 @@ static void destroy_canvas(display_surface *surface)
     zlib_decoder_destroy(surface->zlib_decoder);
     jpeg_decoder_destroy(surface->jpeg_decoder);
 
-    g_free(surface->data);
-    surface->data = NULL;
-
-    surface->canvas->ops->destroy(surface->canvas);
-    surface->canvas = NULL;
+    g_clear_pointer(&surface->data, g_free);
+    g_clear_pointer(&surface->canvas, surface->canvas->ops->destroy);
 }
 
 static display_surface *find_surface(SpiceDisplayChannelPrivate *c, guint32 surface_id)
@@ -1597,8 +1594,7 @@ static void clear_streams(SpiceChannel *channel)
     for (i = 0; i < c->nstreams; i++) {
         destroy_stream(channel, i);
     }
-    g_free(c->streams);
-    c->streams = NULL;
+    g_clear_pointer(&c->streams, g_free);
     c->nstreams = 0;
 }
 
diff --git a/src/channel-main.c b/src/channel-main.c
index 4a1f58a..955b358 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -449,8 +449,7 @@ static void spice_main_channel_reset_agent(SpiceMainChannel *channel)
     c->agent_caps_received = FALSE;
     c->agent_display_config_sent = FALSE;
     c->agent_msg_pos = 0;
-    g_free(c->agent_msg_data);
-    c->agent_msg_data = NULL;
+    g_clear_pointer(&c->agent_msg_data, g_free);
     c->agent_msg_size = 0;
 
     tasks = g_hash_table_get_values(c->file_xfer_tasks);
@@ -916,8 +915,7 @@ static void agent_free_msg_queue(SpiceMainChannel *channel)
         spice_msg_out_unref(out);
     }
 
-    g_queue_free(c->agent_msg_queue);
-    c->agent_msg_queue = NULL;
+    g_clear_pointer(&c->agent_msg_queue, g_queue_free);
 }
 
 static gboolean flush_foreach_remove(gpointer key G_GNUC_UNUSED,
diff --git a/src/channel-playback.c b/src/channel-playback.c
index c97afd8..e931727 100644
--- a/src/channel-playback.c
+++ b/src/channel-playback.c
@@ -114,8 +114,7 @@ static void spice_playback_channel_finalize(GObject *obj)
 
     snd_codec_destroy(&c->codec);
 
-    g_free(c->volume);
-    c->volume = NULL;
+    g_clear_pointer(&c->volume, g_free);
 
     if (G_OBJECT_CLASS(spice_playback_channel_parent_class)->finalize)
         G_OBJECT_CLASS(spice_playback_channel_parent_class)->finalize(obj);
diff --git a/src/channel-record.c b/src/channel-record.c
index 08269c9..09598b7 100644
--- a/src/channel-record.c
+++ b/src/channel-record.c
@@ -108,13 +108,11 @@ static void spice_record_channel_finalize(GObject *obj)
 {
     SpiceRecordChannelPrivate *c = SPICE_RECORD_CHANNEL(obj)->priv;
 
-    g_free(c->last_frame);
-    c->last_frame = NULL;
+    g_clear_pointer(&c->last_frame, g_free);
 
     snd_codec_destroy(&c->codec);
 
-    g_free(c->volume);
-    c->volume = NULL;
+    g_clear_pointer(&c->volume, g_free);
 
     if (G_OBJECT_CLASS(spice_record_channel_parent_class)->finalize)
         G_OBJECT_CLASS(spice_record_channel_parent_class)->finalize(obj);
@@ -166,8 +164,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
 {
     SpiceRecordChannelPrivate *c = SPICE_RECORD_CHANNEL(channel)->priv;
 
-    g_free(c->last_frame);
-    c->last_frame = NULL;
+    g_clear_pointer(&c->last_frame, g_free);
 
     g_coroutine_signal_emit(channel, signals[SPICE_RECORD_STOP], 0);
     c->started = FALSE;
diff --git a/src/channel-smartcard.c b/src/channel-smartcard.c
index 21df98a..09e784d 100644
--- a/src/channel-smartcard.c
+++ b/src/channel-smartcard.c
@@ -161,26 +161,15 @@ static void spice_smartcard_channel_finalize(GObject *obj)
     SpiceSmartcardChannel *channel = SPICE_SMARTCARD_CHANNEL(obj);
     SpiceSmartcardChannelPrivate *c = channel->priv;
 
-    if (c->pending_card_insertions != NULL) {
-        g_hash_table_destroy(c->pending_card_insertions);
-        c->pending_card_insertions = NULL;
-    }
-    if (c->pending_reader_removals != NULL) {
-        g_hash_table_destroy(c->pending_reader_removals);
-        c->pending_reader_removals = NULL;
-    }
+    g_clear_pointer(&c->pending_card_insertions, g_hash_table_destroy);
+    g_clear_pointer(&c->pending_reader_removals, g_hash_table_destroy);
     if (c->message_queue != NULL) {
         g_queue_foreach(c->message_queue, (GFunc)smartcard_message_free, NULL);
         g_queue_free(c->message_queue);
         c->message_queue = NULL;
     }
-    if (c->in_flight_message != NULL) {
-        smartcard_message_free(c->in_flight_message);
-        c->in_flight_message = NULL;
-    }
-
-    g_list_free(c->pending_reader_additions);
-    c->pending_reader_additions = NULL;
+    g_clear_pointer(&c->in_flight_message, smartcard_message_free);
+    g_clear_pointer(&c->pending_reader_additions, g_list_free);
 
     if (G_OBJECT_CLASS(spice_smartcard_channel_parent_class)->finalize)
         G_OBJECT_CLASS(spice_smartcard_channel_parent_class)->finalize(obj);
@@ -199,13 +188,8 @@ static void spice_smartcard_channel_reset(SpiceChannel *channel, gboolean migrat
         g_queue_clear(c->message_queue);
     }
 
-    if (c->in_flight_message != NULL) {
-        smartcard_message_free(c->in_flight_message);
-        c->in_flight_message = NULL;
-    }
-
-    g_list_free(c->pending_reader_additions);
-    c->pending_reader_additions = NULL;
+    g_clear_pointer(&c->in_flight_message, smartcard_message_free);
+    g_clear_pointer(&c->pending_reader_additions, g_list_free);
 
     SPICE_CHANNEL_CLASS(spice_smartcard_channel_parent_class)->channel_reset(channel, migrating);
 }
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 9066b4a..c8a2da9 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -335,8 +335,7 @@ static void spice_usbredir_channel_open_acl_cb(
         spice_usbredir_channel_open_device(channel, &err);
     }
     if (err) {
-        libusb_unref_device(priv->device);
-        priv->device = NULL;
+        g_clear_pointer(&priv->device, libusb_unref_device);
         g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
         priv->spice_device = NULL;
         priv->state  = STATE_DISCONNECTED;
@@ -367,8 +366,7 @@ _open_device_async_cb(GTask *task,
     spice_usbredir_channel_lock(channel);
 
     if (!spice_usbredir_channel_open_device(channel, &err)) {
-        libusb_unref_device(priv->device);
-        priv->device = NULL;
+        g_clear_pointer(&priv->device, libusb_unref_device);
         g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
         priv->spice_device = NULL;
     }
@@ -491,8 +489,7 @@ void spice_usbredir_channel_disconnect_device(SpiceUsbredirChannel *channel)
         }
         /* This also closes the libusb handle we passed from open_device */
         usbredirhost_set_device(priv->host, NULL);
-        libusb_unref_device(priv->device);
-        priv->device = NULL;
+        g_clear_pointer(&priv->device, libusb_unref_device);
         g_boxed_free(spice_usb_device_get_type(), priv->spice_device);
         priv->spice_device = NULL;
         priv->state  = STATE_DISCONNECTED;
diff --git a/src/decode-glz.c b/src/decode-glz.c
index a5fb6c1..b7dd2e6 100644
--- a/src/decode-glz.c
+++ b/src/decode-glz.c
@@ -173,8 +173,7 @@ static void glz_decoder_window_release(SpiceGlzDecoderWindow *w,
 
     while (w->oldest < oldest) {
         slot = w->oldest % w->nimages;
-        glz_image_destroy(w->images[slot]);
-        w->images[slot] = NULL;
+        g_clear_pointer(&w->images[slot], glz_image_destroy);
         w->oldest++;
     }
 }
diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
index d3a40ba..708f976 100644
--- a/src/smartcard-manager.c
+++ b/src/smartcard-manager.c
@@ -127,10 +127,7 @@ static void spice_smartcard_manager_finalize(GObject *gobject)
     }
 
 #ifdef USE_SMARTCARD
-    if (priv->software_reader != NULL) {
-        vreader_free(priv->software_reader);
-        priv->software_reader = NULL;
-    }
+    g_clear_pointer(&priv->software_reader, vreader_free);
 #endif
 
     /* Chain up to the parent class */
@@ -275,8 +272,7 @@ static gboolean smartcard_monitor_dispatch(VEvent *event, gpointer user_data)
         case VEVENT_READER_REMOVE:
             if (spice_smartcard_reader_is_software((SpiceSmartcardReader*)event->reader)) {
                 g_warn_if_fail(manager->priv->software_reader != NULL);
-                vreader_free(manager->priv->software_reader);
-                manager->priv->software_reader = NULL;
+                g_clear_pointer(&manager->priv->software_reader, vreader_free);
             }
             SPICE_DEBUG("smartcard: reader-removed");
             g_signal_emit(G_OBJECT(user_data),
@@ -355,10 +351,7 @@ static void smartcard_source_finalize(GSource *source)
 {
     SmartcardSource *smartcard_source = (SmartcardSource *)source;
 
-    if (smartcard_source->pending_event) {
-        vevent_delete(smartcard_source->pending_event);
-        smartcard_source->pending_event = NULL;
-    }
+    g_clear_pointer(&smartcard_source->pending_event, vevent_delete);
 }
 
 static GSource *smartcard_monitor_source_new(void)
diff --git a/src/spice-audio.c b/src/spice-audio.c
index 86a5138..c514d30 100644
--- a/src/spice-audio.c
+++ b/src/spice-audio.c
@@ -65,10 +65,7 @@ static void spice_audio_finalize(GObject *gobject)
     SpiceAudio *self = SPICE_AUDIO(gobject);
     SpiceAudioPrivate *priv = self->priv;
 
-    if (priv->main_context) {
-        g_main_context_unref(priv->main_context);
-        priv->main_context = NULL;
-    }
+    g_clear_pointer(&priv->main_context, g_main_context_unref);
 
     if (G_OBJECT_CLASS(spice_audio_parent_class)->finalize)
         G_OBJECT_CLASS(spice_audio_parent_class)->finalize(gobject);
diff --git a/src/spice-channel.c b/src/spice-channel.c
index e9c5a1b..19237b3 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1684,10 +1684,7 @@ restart:
             goto restep;
         }
 
-        if (serverin) {
-            g_free(serverin);
-            serverin = NULL;
-        }
+        g_clear_pointer(&serverin, g_free);
 
         CHANNEL_DEBUG(channel, "Client step result %d. Data %d bytes %p '%s'", err, clientoutlen, clientout, clientout);
 
@@ -1739,8 +1736,7 @@ restart:
 
         /* This server call shows complete, and earlier client step was OK */
         if (complete) {
-            g_free(serverin);
-            serverin = NULL;
+            g_clear_pointer(&serverin, g_free);
             if (err == SASL_CONTINUE) /* something went wrong */
                 goto complete;
             break;
@@ -2702,18 +2698,9 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
     }
 #endif
 
-    spice_openssl_verify_free(c->sslverify);
-    c->sslverify = NULL;
-
-    if (c->ssl) {
-        SSL_free(c->ssl);
-        c->ssl = NULL;
-    }
-
-    if (c->ctx) {
-        SSL_CTX_free(c->ctx);
-        c->ctx = NULL;
-    }
+    g_clear_pointer(&c->sslverify, spice_openssl_verify_free);
+    g_clear_pointer(&c->ssl, SSL_free);
+    g_clear_pointer(&c->ctx, SSL_CTX_free);
 
     g_clear_object(&c->conn);
     g_clear_object(&c->sock);
@@ -2723,8 +2710,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
     c->auth_needs_username = FALSE;
     c->auth_needs_password = FALSE;
 
-    g_free(c->peer_msg);
-    c->peer_msg = NULL;
+    g_clear_pointer(&c->peer_msg, g_free);
     c->peer_pos = 0;
 
     STATIC_MUTEX_LOCK(c->xmit_queue_lock);
diff --git a/src/spice-gstaudio.c b/src/spice-gstaudio.c
index a7c3c24..9a92452 100644
--- a/src/spice-gstaudio.c
+++ b/src/spice-gstaudio.c
@@ -70,19 +70,11 @@ void stream_dispose(struct stream *s)
 {
     if (s->pipe) {
         gst_element_set_state(s->pipe, GST_STATE_NULL);
-        gst_object_unref(s->pipe);
-        s->pipe = NULL;
+        g_clear_pointer(&s->pipe, gst_object_unref);
     }
 
-    if (s->src) {
-        gst_object_unref(s->src);
-        s->src = NULL;
-    }
-
-    if (s->sink) {
-        gst_object_unref(s->sink);
-        s->sink = NULL;
-    }
+    g_clear_pointer(&s->src, gst_object_unref);
+    g_clear_pointer(&s->sink, gst_object_unref);
 }
 
 static void spice_gstaudio_dispose(GObject *obj)
@@ -210,8 +202,7 @@ static void record_start(SpiceRecordChannel *channel, gint format, gint channels
         (p->record.rate != frequency ||
          p->record.channels != channels)) {
         record_stop(gstaudio);
-        gst_object_unref(p->record.pipe);
-        p->record.pipe = NULL;
+        g_clear_pointer(&p->record.pipe, gst_object_unref);
     }
 
     if (!p->record.pipe) {
@@ -244,10 +235,8 @@ static void record_start(SpiceRecordChannel *channel, gint format, gint channels
                                       G_CALLBACK(record_new_buffer), gstaudio, 0);
 
 cleanup:
-        if (error != NULL && p->record.pipe != NULL) {
-            gst_object_unref(p->record.pipe);
-            p->record.pipe = NULL;
-        }
+        if (error != NULL)
+            g_clear_pointer(&p->record.pipe, gst_object_unref);
         g_clear_error(&error);
         g_free(audio_caps);
         g_free(pipeline);
@@ -303,8 +292,7 @@ static void playback_start(SpicePlaybackChannel *channel, gint format, gint chan
         (p->playback.rate != frequency ||
          p->playback.channels != channels)) {
         playback_stop(gstaudio);
-        gst_object_unref(p->playback.pipe);
-        p->playback.pipe = NULL;
+        g_clear_pointer(&p->playback.pipe, gst_object_unref);
     }
 
     if (!p->playback.pipe) {
@@ -328,10 +316,8 @@ static void playback_start(SpicePlaybackChannel *channel, gint format, gint chan
         p->playback.channels = channels;
 
 cleanup:
-        if (error != NULL && p->playback.pipe != NULL) {
-            gst_object_unref(p->playback.pipe);
-            p->playback.pipe = NULL;
-        }
+        if (error != NULL)
+            g_clear_pointer(&p->playback.pipe, gst_object_unref);
         g_clear_error(&error);
         g_free(audio_caps);
         g_free(pipeline);
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 7370599..27623f0 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -303,8 +303,7 @@ static void spice_gtk_session_finalize(GObject *gobject)
 
     /* release stuff */
     for (i = 0; i < CLIPBOARD_LAST; ++i) {
-        g_free(s->clip_targets[i]);
-        s->clip_targets[i] = NULL;
+        g_clear_pointer(&s->clip_targets[i], g_free);
     }
 
     /* Chain up to the parent class */
@@ -792,8 +791,7 @@ static void clipboard_get(GtkClipboard *clipboard,
     gdk_threads_enter();
 
 cleanup:
-    g_main_loop_unref(ri.loop);
-    ri.loop = NULL;
+    g_clear_pointer(&ri.loop, g_main_loop_unref);
     g_signal_handler_disconnect(s->main, clipboard_handler);
     g_signal_handler_disconnect(s->main, agent_handler);
 }
diff --git a/src/spice-option.c b/src/spice-option.c
index 70d0277..46ae530 100644
--- a/src/spice-option.c
+++ b/src/spice-option.c
@@ -99,8 +99,7 @@ static gboolean parse_disable_effects(const gchar *option_name, const gchar *val
              */
             g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
                     _("invalid effect name (%s), must be 'wallpaper', 'font-smooth', 'animation' or 'all'"), *it);
-            g_strfreev(disable_effects);
-            disable_effects = NULL;
+            g_clear_pointer(&disable_effects, g_strfreev);
             return FALSE;
         }
     }
diff --git a/src/spice-pulse.c b/src/spice-pulse.c
index 6bc3014..fd5fe91 100644
--- a/src/spice-pulse.c
+++ b/src/spice-pulse.c
@@ -131,21 +131,10 @@ static void spice_pulse_dispose(GObject *obj)
     SPICE_DEBUG("%s", __FUNCTION__);
     p = pulse->priv;
 
-    if (p->playback.uncork_op)
-        pa_operation_unref(p->playback.uncork_op);
-    p->playback.uncork_op = NULL;
-
-    if (p->playback.cork_op)
-        pa_operation_unref(p->playback.cork_op);
-    p->playback.cork_op = NULL;
-
-    if (p->record.uncork_op)
-        pa_operation_unref(p->record.uncork_op);
-    p->record.uncork_op = NULL;
-
-    if (p->record.cork_op)
-        pa_operation_unref(p->record.cork_op);
-    p->record.cork_op = NULL;
+    g_clear_pointer(&p->playback.uncork_op, pa_operation_unref);
+    g_clear_pointer(&p->playback.cork_op, pa_operation_unref);
+    g_clear_pointer(&p->record.uncork_op, pa_operation_unref);
+    g_clear_pointer(&p->record.cork_op, pa_operation_unref);
 
     if (p->results != NULL)
         spice_pulse_complete_all_async_tasks(pulse, "PulseAudio is being dispose");
@@ -194,8 +183,7 @@ static void pulse_uncork_cb(pa_stream *pastream, int success, void *data)
     if (!success)
         g_warning("pulseaudio uncork operation failed");
 
-    pa_operation_unref(s->uncork_op);
-    s->uncork_op = NULL;
+    g_clear_pointer(&s->uncork_op, pa_operation_unref);
 }
 
 static void stream_uncork(SpicePulse *pulse, struct stream *s)
@@ -207,8 +195,7 @@ static void stream_uncork(SpicePulse *pulse, struct stream *s)
 
     if (s->cork_op) {
         pa_operation_cancel(s->cork_op);
-        pa_operation_unref(s->cork_op);
-        s->cork_op = NULL;
+        g_clear_pointer(&s->cork_op, pa_operation_unref);
     }
 
     if (pa_stream_is_corked(s->stream) && !s->uncork_op) {
@@ -227,8 +214,7 @@ static void pulse_flush_cb(pa_stream *pastream, int success, void *data)
     if (!success)
         g_warning("pulseaudio flush operation failed");
 
-    pa_operation_unref(s->cork_op);
-    s->cork_op = NULL;
+    g_clear_pointer(&s->cork_op, pa_operation_unref);
 }
 
 static void pulse_cork_flush_cb(pa_stream *pastream, int success, void *data)
@@ -253,8 +239,7 @@ static void pulse_cork_cb(pa_stream *pastream, int success, void *data)
     if (!success)
         g_warning("pulseaudio cork operation failed");
 
-    pa_operation_unref(s->cork_op);
-    s->cork_op = NULL;
+    g_clear_pointer(&s->cork_op, pa_operation_unref);
 }
 
 static void stream_cork(SpicePulse *pulse, struct stream *s, gboolean with_flush)
@@ -264,8 +249,7 @@ static void stream_cork(SpicePulse *pulse, struct stream *s, gboolean with_flush
 
     if (s->uncork_op) {
         pa_operation_cancel(s->uncork_op);
-        pa_operation_unref(s->uncork_op);
-        s->uncork_op = NULL;
+        g_clear_pointer(&s->uncork_op, pa_operation_unref);
     }
 
     if (!pa_stream_is_corked(s->stream) && !s->cork_op) {
@@ -288,8 +272,7 @@ static void stream_stop(SpicePulse *pulse, struct stream *s)
         g_warning("pa_stream_disconnect() failed: %s",
                   pa_strerror(pa_context_errno(p->context)));
     }
-    pa_stream_unref(s->stream);
-    s->stream = NULL;
+    g_clear_pointer(&s->stream, pa_stream_unref);
 }
 
 static void stream_state_callback(pa_stream *s, void *userdata)
@@ -928,8 +911,7 @@ static gboolean free_async_task(gpointer user_data)
 
     if (task->pa_op != NULL) {
         pa_operation_cancel(task->pa_op);
-        pa_operation_unref(task->pa_op);
-        task->pa_op = NULL;
+        g_clear_pointer(&task->pa_op, pa_operation_unref);
     }
 
     if (task->pulse) {
@@ -966,8 +948,7 @@ static void cancel_task(GCancellable *cancellable, gpointer user_data)
      * cancelled task operation before free_async_task is called */
     if (task->pa_op != NULL) {
         pa_operation_cancel(task->pa_op);
-        pa_operation_unref(task->pa_op);
-        task->pa_op = NULL;
+        g_clear_pointer(&task->pa_op, pa_operation_unref);
     }
 
     /* Clear the pending_restore_task reference to avoid triggering a
@@ -1034,8 +1015,7 @@ static void spice_pulse_complete_all_async_tasks(SpicePulse *pulse, const gchar
         complete_task(pulse, task, err_msg);
         free_async_task(task);
     }
-    g_list_free(p->results);
-    p->results = NULL;
+    g_clear_pointer(&p->results, g_list_free);
     SPICE_DEBUG("All async tasks completed");
 }
 
diff --git a/src/spice-session.c b/src/spice-session.c
index 9bf3f40..e02d684 100644
--- a/src/spice-session.c
+++ b/src/spice-session.c
@@ -317,8 +317,7 @@ session_disconnect(SpiceSession *self, gboolean keep_main)
 
     s->connection_id = 0;
 
-    g_free(s->name);
-    s->name = NULL;
+    g_clear_pointer(&s->name, g_free);
     memset(s->uuid, 0, sizeof(s->uuid));
 
     spice_session_abort_migration(self);
@@ -1762,11 +1761,9 @@ void spice_session_abort_migration(SpiceSession *session)
     }
 
 end:
-    g_list_free(s->migration_left);
-    s->migration_left = NULL;
+    g_clear_pointer(&s->migration_left, g_list_free);
     session_disconnect(s->migration, FALSE);
-    g_object_unref(s->migration);
-    s->migration = NULL;
+    g_clear_pointer(&s->migration, g_object_unref);
 
     s->migrate_wait_init = FALSE;
     if (s->after_main_init) {
@@ -1805,8 +1802,7 @@ void spice_session_channel_migrate(SpiceSession *session, SpiceChannel *channel)
     if (g_list_length(s->migration_left) == 0) {
         CHANNEL_DEBUG(channel, "migration: all channel migrated, success");
         session_disconnect(s->migration, FALSE);
-        g_object_unref(s->migration);
-        s->migration = NULL;
+        g_clear_pointer(&s->migration, g_object_unref);
         spice_session_set_migration_state(session, SPICE_SESSION_MIGRATION_NONE);
     }
 }
diff --git a/src/spice-widget-cairo.c b/src/spice-widget-cairo.c
index 8c45524..5d93a9f 100644
--- a/src/spice-widget-cairo.c
+++ b/src/spice-widget-cairo.c
@@ -53,14 +53,9 @@ void spicex_image_destroy(SpiceDisplay *display)
 {
     SpiceDisplayPrivate *d = display->priv;
 
-    if (d->ximage) {
-        cairo_surface_destroy(d->ximage);
-        d->ximage = NULL;
-    }
-    if (d->convert && d->data) {
-        g_free(d->data);
-        d->data = NULL;
-    }
+    g_clear_pointer(&d->ximage, cairo_surface_destroy);
+    if (d->convert)
+        g_clear_pointer(&d->data, g_free);
     d->convert = FALSE;
 }
 
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 72a0355..f30b80f 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -432,12 +432,8 @@ static void spice_display_finalize(GObject *obj)
 
     SPICE_DEBUG("Finalize spice display");
 
-    if (d->grabseq) {
-        spice_grab_sequence_free(d->grabseq);
-        d->grabseq = NULL;
-    }
-    g_free(d->activeseq);
-    d->activeseq = NULL;
+    g_clear_pointer(&d->grabseq, spice_grab_sequence_free);
+    g_clear_pointer(&d->activeseq, g_free);
 
     g_clear_object(&d->show_cursor);
     g_clear_object(&d->mouse_cursor);
@@ -825,10 +821,7 @@ static void try_keyboard_ungrab(SpiceDisplay *display)
     SPICE_DEBUG("ungrab keyboard");
     gdk_keyboard_ungrab(GDK_CURRENT_TIME);
 #ifdef G_OS_WIN32
-    if (d->keyboard_hook != NULL) {
-        UnhookWindowsHookEx(d->keyboard_hook);
-        d->keyboard_hook = NULL;
-    }
+    g_clear_pointer(&d->keyboard_hook, UnhookWindowsHookEx);
 #endif
     d->keyboard_grab_active = false;
     g_signal_emit(widget, signals[SPICE_DISPLAY_KEYBOARD_GRAB], 0, false);
@@ -2354,8 +2347,7 @@ static void cursor_set(SpiceCursorChannel *channel,
 #endif
     if (d->show_cursor) {
         /* unhide */
-        g_object_unref(d->show_cursor);
-        d->show_cursor = NULL;
+        g_clear_pointer(&d->show_cursor, g_object_unref);
         if (d->mouse_mode == SPICE_MOUSE_MODE_SERVER) {
             /* keep a hidden cursor, will be shown in cursor_move() */
             d->show_cursor = cursor;
diff --git a/src/usb-acl-helper.c b/src/usb-acl-helper.c
index 487e1ee..fa845be 100644
--- a/src/usb-acl-helper.c
+++ b/src/usb-acl-helper.c
@@ -58,15 +58,8 @@ static void spice_usb_acl_helper_cleanup(SpiceUsbAclHelper *self)
 
     g_clear_object(&priv->task);
 
-    if (priv->in_ch) {
-        g_io_channel_unref(priv->in_ch);
-        priv->in_ch = NULL;
-    }
-
-    if (priv->out_ch) {
-        g_io_channel_unref(priv->out_ch);
-        priv->out_ch = NULL;
-    }
+    g_clear_pointer(&priv->in_ch, g_io_channel_unref);
+    g_clear_pointer(&priv->out_ch, g_io_channel_unref);
 }
 
 static void spice_usb_acl_helper_finalize(GObject *gobject)
diff --git a/src/wocky-http-proxy.c b/src/wocky-http-proxy.c
index 33d57d8..f62f1fb 100644
--- a/src/wocky-http-proxy.c
+++ b/src/wocky-http-proxy.c
@@ -416,8 +416,7 @@ request_write_cb (GObject *source,
 
    if (data->offset == data->length)
     {
-      g_free (data->buffer);
-      data->buffer = NULL;
+      g_clear_pointer(&data->buffer, g_free);
 
       g_data_input_stream_read_until_async (data->data_in,
           HTTP_END_MARKER,
commit c9c2cf308167c391a4cfb381adb0b3b5ea29e03d
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Wed Apr 6 15:40:11 2016 +0200

    Use g_clear_object if possible
    
    Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 8ae0e4d..e9c5a1b 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -155,10 +155,7 @@ static void spice_channel_dispose(GObject *gobject)
 
     spice_channel_disconnect(channel, SPICE_CHANNEL_CLOSED);
 
-    if (c->session) {
-         g_object_unref(c->session);
-         c->session = NULL;
-    }
+    g_clear_object(&c->session);
 
     g_clear_error(&c->error);
 
@@ -2718,11 +2715,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
         c->ctx = NULL;
     }
 
-    if (c->conn) {
-        g_object_unref(c->conn);
-        c->conn = NULL;
-    }
-
+    g_clear_object(&c->conn);
     g_clear_object(&c->sock);
 
     c->fd = -1;
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 8ca8631..72a0355 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -439,20 +439,9 @@ static void spice_display_finalize(GObject *obj)
     g_free(d->activeseq);
     d->activeseq = NULL;
 
-    if (d->show_cursor) {
-        g_object_unref(d->show_cursor);
-        d->show_cursor = NULL;
-    }
-
-    if (d->mouse_cursor) {
-        g_object_unref(d->mouse_cursor);
-        d->mouse_cursor = NULL;
-    }
-
-    if (d->mouse_pixbuf) {
-        g_object_unref(d->mouse_pixbuf);
-        d->mouse_pixbuf = NULL;
-    }
+    g_clear_object(&d->show_cursor);
+    g_clear_object(&d->mouse_cursor);
+    g_clear_object(&d->mouse_pixbuf);
 
     G_OBJECT_CLASS(spice_display_parent_class)->finalize(obj);
 }
@@ -2343,10 +2332,7 @@ static void cursor_set(SpiceCursorChannel *channel,
 
     cursor_invalidate(display);
 
-    if (d->mouse_pixbuf) {
-        g_object_unref(d->mouse_pixbuf);
-        d->mouse_pixbuf = NULL;
-    }
+    g_clear_object(&d->mouse_pixbuf);
 
     if (rgba != NULL) {
         d->mouse_pixbuf = gdk_pixbuf_new_from_data(g_memdup(rgba, width * height * 4),
diff --git a/src/wocky-http-proxy.c b/src/wocky-http-proxy.c
index a1a030a..33d57d8 100644
--- a/src/wocky-http-proxy.c
+++ b/src/wocky-http-proxy.c
@@ -222,8 +222,7 @@ wocky_http_proxy_connect (GProxy *proxy,
   g_free (buffer);
   buffer = g_data_input_stream_read_until (data_in, HTTP_END_MARKER, NULL,
       cancellable, error);
-  g_object_unref (data_in);
-  data_in = NULL;
+  g_clear_object(&data_in);
 
   if (buffer == NULL)
     {
commit 3c6c563328b67d8dbc089d24fead118dc9ed3667
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Wed Apr 6 15:40:10 2016 +0200

    Use g_object_unref instead of gdk_cursor_unref
    
    GdkCursor is GObject and gdk_cursor_unref has been deprecated since 3.0
    
    Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

diff --git a/src/spice-widget.c b/src/spice-widget.c
index f605439..8ca8631 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -440,12 +440,12 @@ static void spice_display_finalize(GObject *obj)
     d->activeseq = NULL;
 
     if (d->show_cursor) {
-        gdk_cursor_unref(d->show_cursor);
+        g_object_unref(d->show_cursor);
         d->show_cursor = NULL;
     }
 
     if (d->mouse_cursor) {
-        gdk_cursor_unref(d->mouse_cursor);
+        g_object_unref(d->mouse_cursor);
         d->mouse_cursor = NULL;
     }
 
@@ -987,7 +987,7 @@ static GdkGrabStatus do_pointer_grab(SpiceDisplay *display)
     }
 
 end:
-    gdk_cursor_unref(blank);
+    g_object_unref(blank);
     return status;
 }
 
@@ -2368,7 +2368,7 @@ static void cursor_set(SpiceCursorChannel *channel,
 #endif
     if (d->show_cursor) {
         /* unhide */
-        gdk_cursor_unref(d->show_cursor);
+        g_object_unref(d->show_cursor);
         d->show_cursor = NULL;
         if (d->mouse_mode == SPICE_MOUSE_MODE_SERVER) {
             /* keep a hidden cursor, will be shown in cursor_move() */
@@ -2377,7 +2377,7 @@ static void cursor_set(SpiceCursorChannel *channel,
         }
     }
 
-    gdk_cursor_unref(d->mouse_cursor);
+    g_object_unref(d->mouse_cursor);
     d->mouse_cursor = cursor;
 
     update_mouse_pointer(display);
@@ -2493,7 +2493,7 @@ static void cursor_move(SpiceCursorChannel *channel, gint x, gint y, gpointer da
 
     /* apparently we have to restore cursor when "cursor_move" */
     if (d->show_cursor != NULL) {
-        gdk_cursor_unref(d->mouse_cursor);
+        g_object_unref(d->mouse_cursor);
         d->mouse_cursor = d->show_cursor;
         d->show_cursor = NULL;
         update_mouse_pointer(display);
commit 6eb50944b2a082ec0d0e83a4d1f6a338e2956285
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Wed Apr 6 15:40:09 2016 +0200

    Use GMutex instead of GStaticMutex
    
    Since GLib 2.32 GMutex can be statically allocated, so GStaticMutex has
    been deprecated.
    
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/src/desktop-integration.c b/src/desktop-integration.c
index 01300e8..529fb05 100644
--- a/src/desktop-integration.c
+++ b/src/desktop-integration.c
@@ -196,17 +196,17 @@ static void spice_desktop_integration_class_init(SpiceDesktopIntegrationClass *k
 SpiceDesktopIntegration *spice_desktop_integration_get(SpiceSession *session)
 {
     SpiceDesktopIntegration *self;
-    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+    static GMutex mutex;
 
     g_return_val_if_fail(session != NULL, NULL);
 
-    g_static_mutex_lock(&mutex);
+    g_mutex_lock(&mutex);
     self = g_object_get_data(G_OBJECT(session), "spice-desktop");
     if (self == NULL) {
         self = g_object_new(SPICE_TYPE_DESKTOP_INTEGRATION, NULL);
         g_object_set_data_full(G_OBJECT(session), "spice-desktop", self, g_object_unref);
     }
-    g_static_mutex_unlock(&mutex);
+    g_mutex_unlock(&mutex);
 
     return self;
 }
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 380b0bb..7370599 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -1133,15 +1133,15 @@ SpiceGtkSession *spice_gtk_session_get(SpiceSession *session)
     g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
 
     SpiceGtkSession *self;
-    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+    static GMutex mutex;
 
-    g_static_mutex_lock(&mutex);
+    g_mutex_lock(&mutex);
     self = g_object_get_data(G_OBJECT(session), "spice-gtk-session");
     if (self == NULL) {
         self = g_object_new(SPICE_TYPE_GTK_SESSION, "session", session, NULL);
         g_object_set_data_full(G_OBJECT(session), "spice-gtk-session", self, g_object_unref);
     }
-    g_static_mutex_unlock(&mutex);
+    g_mutex_unlock(&mutex);
 
     return SPICE_GTK_SESSION(self);
 }
diff --git a/src/spice-session.c b/src/spice-session.c
index 6a0edae..9bf3f40 100644
--- a/src/spice-session.c
+++ b/src/spice-session.c
@@ -2641,18 +2641,18 @@ SpiceURI *spice_session_get_proxy_uri(SpiceSession *session)
  **/
 SpiceAudio *spice_audio_get(SpiceSession *session, GMainContext *context)
 {
-    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+    static GMutex mutex;
     SpiceAudio *self;
 
     g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
 
-    g_static_mutex_lock(&mutex);
+    g_mutex_lock(&mutex);
     self = session->priv->audio_manager;
     if (self == NULL) {
         self = spice_audio_new(session, context, NULL);
         session->priv->audio_manager = self;
     }
-    g_static_mutex_unlock(&mutex);
+    g_mutex_unlock(&mutex);
 
     return self;
 }
@@ -2675,19 +2675,19 @@ SpiceUsbDeviceManager *spice_usb_device_manager_get(SpiceSession *session,
                                                     GError **err)
 {
     SpiceUsbDeviceManager *self;
-    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+    static GMutex mutex;
 
     g_return_val_if_fail(SPICE_IS_SESSION(session), NULL);
     g_return_val_if_fail(err == NULL || *err == NULL, NULL);
 
-    g_static_mutex_lock(&mutex);
+    g_mutex_lock(&mutex);
     self = session->priv->usb_manager;
     if (self == NULL) {
         self = g_initable_new(SPICE_TYPE_USB_DEVICE_MANAGER, NULL, err,
                               "session", session, NULL);
         session->priv->usb_manager = self;
     }
-    g_static_mutex_unlock(&mutex);
+    g_mutex_unlock(&mutex);
 
     return self;
 }
diff --git a/src/usbutil.c b/src/usbutil.c
index 24330b2..6cd8148 100644
--- a/src/usbutil.c
+++ b/src/usbutil.c
@@ -51,7 +51,7 @@ typedef struct _usb_vendor_info {
     char name[VENDOR_NAME_LEN];
 } usb_vendor_info;
 
-static GStaticMutex usbids_load_mutex = G_STATIC_MUTEX_INIT;
+static GMutex usbids_load_mutex;
 static int usbids_vendor_count = 0; /* < 0: failed, 0: empty, > 0: loaded */
 static usb_vendor_info *usbids_vendor_info = NULL;
 
@@ -215,7 +215,7 @@ static gboolean spice_usbutil_load_usbids(void)
 {
     gboolean success = FALSE;
 
-    g_static_mutex_lock(&usbids_load_mutex);
+    g_mutex_lock(&usbids_load_mutex);
     if (usbids_vendor_count) {
         success = usbids_vendor_count > 0;
         goto leave;
@@ -242,7 +242,7 @@ static gboolean spice_usbutil_load_usbids(void)
 #endif
 
 leave:
-    g_static_mutex_unlock(&usbids_load_mutex);
+    g_mutex_unlock(&usbids_load_mutex);
     return success;
 }
 
commit 60d81a2936597cbf968e75ce590aa526c17b125e
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Wed Apr 6 15:40:08 2016 +0200

    Use GDK_VERSION_MAX_ALLOWED
    
    In order to avoid using a too new Gtk API.
    
    Taken from virt-viewer 4c4a43c61db60ac815c0bc66730fa0a9a1571103
    
    Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

diff --git a/configure.ac b/configure.ac
index 817aaab..ce80d88 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,6 +124,7 @@ AC_ARG_WITH([gtk],
 
 case "$with_gtk" in
   3.0) GTK_REQUIRED=3.10
+       GTK_ENCODED_VERSION="GDK_VERSION_3_10"
        ;;
   no)
        AS_IF([test x$enable_gtk_doc = xyes],
@@ -134,7 +135,9 @@ AC_SUBST([GTK_REQUIRED])
 AM_CONDITIONAL([WITH_GTK],[test "$with_gtk" != "no"])
 
 AS_IF([test "x$with_gtk" != "xno"],
-      [PKG_CHECK_MODULES(GTK, gtk+-3.0 >= $GTK_REQUIRED epoxy)])
+      [PKG_CHECK_MODULES(GTK, gtk+-3.0 >= $GTK_REQUIRED epoxy)]
+      [GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=$GTK_ENCODED_VERSION \
+                               -DGDK_VERSION_MAX_ALLOWED=$GTK_ENCODED_VERSION"])
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
 SPICE_GTK_REQUIRES="${SPICE_GTK_REQUIRES} gtk+-3.0 >= $GTK_REQUIRED"
commit 69db99b95657a66b9febe3790f32e3a568673e00
Author: Pavel Grunt <pgrunt at redhat.com>
Date:   Wed Apr 6 15:40:07 2016 +0200

    Use GLIB_VERSION_MAX_ALLOWED
    
    In order to avoid using a too new GLib API.
    
    Taken from virt-viewer 96d120903f0b95d49642e58d4f796b4f62aa8b20
    
    Acked-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>

diff --git a/configure.ac b/configure.ac
index 4227fd8..817aaab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,7 +166,13 @@ fi
 
 AC_CHECK_FUNCS(clearenv strtok_r)
 
-PKG_CHECK_MODULES(GLIB2, glib-2.0)
+# Keep these two definitions in agreement.
+GLIB2_REQUIRED="2.36"
+GLIB2_ENCODED_VERSION="GLIB_VERSION_2_36"
+
+PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_REQUIRED)
+GLIB2_CFLAGS="$GLIB2_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=$GLIB2_ENCODED_VERSION \
+  -DGLIB_VERSION_MAX_ALLOWED=$GLIB2_ENCODED_VERSION"
 AC_SUBST(GLIB2_CFLAGS)
 AC_SUBST(GLIB2_LIBS)
 


More information about the Spice-commits mailing list