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