[evolution-data-server] I#265 - code-cleanup: Remove unnecessary NULL pointer checks



commit e48a83db63875e0ac74ce5ebdb32e10a0c54327f
Author: Markus Elfring <elfring users sourceforge net>
Date:   Wed Nov 11 08:39:02 2020 +0100

    I#265 - code-cleanup: Remove unnecessary NULL pointer checks
    
    These changes were generated by using the software “Coccinelle 1.0.8”.
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/265

 .../backends/file/e-book-backend-file.c            |  5 +--
 .../backends/ldap/e-book-backend-ldap.c            | 40 +++++----------------
 src/addressbook/libebook/e-book-client-view.c      | 18 ++--------
 src/addressbook/libebook/e-book-client.c           |  5 +--
 src/addressbook/libebook/e-book-view.c             |  6 +---
 src/addressbook/libebook/e-book.c                  |  5 +--
 src/addressbook/libebook/e-destination.c           | 11 ++----
 .../libedata-book/e-book-backend-sqlitedb.c        | 10 ++----
 src/addressbook/libedata-book/e-book-cache.c       |  5 +--
 src/addressbook/libedata-book/e-book-sqlite.c      |  5 +--
 src/addressbook/libedata-book/e-data-book-view.c   |  5 +--
 src/addressbook/libedata-book/e-data-book.c        | 16 ++-------
 .../evolution-addressbook-factory-subprocess.c     |  5 +--
 src/calendar/backends/file/e-cal-backend-file.c    |  8 ++---
 src/calendar/backends/http/e-cal-backend-http.c    | 10 ++----
 src/calendar/backends/weather/e-weather-source.c   |  6 +---
 src/calendar/libecal/e-cal-client-view.c           | 12 ++-----
 src/calendar/libecal/e-reminder-watcher.c          |  5 +--
 src/calendar/libedata-cal/e-data-cal-view.c        |  5 +--
 src/calendar/libedata-cal/e-data-cal.c             | 10 ++----
 .../evolution-calendar-factory-subprocess.c        |  5 +--
 src/camel/camel-certdb.c                           | 10 ++----
 src/camel/camel-cipher-context.c                   |  6 +---
 src/camel/camel-data-wrapper.c                     |  5 +--
 src/camel/camel-db.c                               | 10 ++----
 src/camel/camel-debug.c                            |  5 +--
 src/camel/camel-filter-driver.c                    | 26 +++-----------
 src/camel/camel-folder.c                           |  8 ++---
 src/camel/camel-index.c                            | 10 ++----
 src/camel/camel-medium.c                           |  6 +---
 src/camel/camel-message-info-base.c                |  5 +--
 src/camel/camel-mime-filter-html.c                 |  6 +---
 src/camel/camel-mime-filter-index.c                | 12 ++-----
 src/camel/camel-mime-filter-progress.c             |  6 +---
 src/camel/camel-sasl-ntlm.c                        |  3 +-
 src/camel/camel-sasl.c                             |  6 +---
 src/camel/camel-sexp.c                             |  3 +-
 src/camel/camel-store.c                            | 10 ++----
 src/camel/camel-stream-buffer.c                    |  6 +---
 src/camel/camel-text-index.c                       | 41 ++++------------------
 src/camel/camel-vee-data-cache.c                   | 18 ++--------
 src/camel/camel-vee-folder.c                       |  4 +--
 src/camel/providers/imapx/camel-imapx-folder.c     | 11 ++----
 src/camel/providers/imapx/camel-imapx-server.c     | 34 ++++--------------
 src/camel/providers/imapx/camel-imapx-utils.c      |  4 +--
 src/camel/providers/local/camel-local-summary.c    |  6 +---
 src/camel/providers/local/camel-mbox-summary.c     |  3 +-
 src/camel/providers/nntp/camel-nntp-folder.c       |  5 +--
 src/camel/providers/nntp/camel-nntp-stream.c       |  5 +--
 src/camel/providers/nntp/camel-nntp-summary.c      | 15 ++------
 src/camel/providers/pop3/camel-pop3-engine.c       |  5 +--
 src/camel/providers/pop3/camel-pop3-folder.c       | 10 ++----
 src/camel/providers/pop3/camel-pop3-stream.c       |  5 +--
 src/examples/cursor/cursor-example.c               | 11 ++----
 src/libebackend/e-backend.c                        |  5 +--
 src/libebackend/e-cache.c                          | 10 ++----
 src/libebackend/e-collection-backend.c             |  5 +--
 src/libebackend/e-server-side-source.c             |  5 +--
 src/libebackend/e-source-registry-server.c         |  5 +--
 src/libebackend/e-user-prompter-server.c           |  6 +---
 src/libedataserver/e-categories.c                  | 11 ++----
 src/libedataserver/e-client.c                      |  7 +---
 src/libedataserver/e-sexp.c                        |  3 +-
 src/libedataserver/e-source-camel.c                |  6 +---
 src/libedataserver/e-source-local.c                |  6 +---
 src/libedataserver/e-source-mail-signature.c       |  6 +---
 src/libedataserver/e-source-registry.c             | 17 ++-------
 src/libedataserver/e-source.c                      | 15 ++------
 src/libedataserver/e-xml-document.c                | 10 ++----
 .../evolution-source-registry-migrate-sources.c    | 38 ++++----------------
 70 files changed, 129 insertions(+), 543 deletions(-)
---
diff --git a/src/addressbook/backends/file/e-book-backend-file.c 
b/src/addressbook/backends/file/e-book-backend-file.c
index 51fb5a7fa..d7a5c6682 100644
--- a/src/addressbook/backends/file/e-book-backend-file.c
+++ b/src/addressbook/backends/file/e-book-backend-file.c
@@ -1055,10 +1055,7 @@ book_backend_file_dispose (GObject *object)
                bf->priv->cursors = NULL;
        }
 
-       if (bf->priv->sqlitedb) {
-               g_object_unref (bf->priv->sqlitedb);
-               bf->priv->sqlitedb = NULL;
-       }
+       g_clear_object (&bf->priv->sqlitedb);
 
        g_rw_lock_writer_unlock (&(bf->priv->lock));
 
diff --git a/src/addressbook/backends/ldap/e-book-backend-ldap.c 
b/src/addressbook/backends/ldap/e-book-backend-ldap.c
index 680b396a8..c37d67a07 100644
--- a/src/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/src/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -867,10 +867,7 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl,
 
                if (ldap_error == LDAP_PROTOCOL_ERROR) {
                        g_warning ("failed to bind using either v3 or v2 binds.");
-                       if (blpriv->ldap) {
-                               ldap_unbind (blpriv->ldap);
-                               blpriv->ldap = NULL;
-                       }
+                       g_clear_pointer (&blpriv->ldap, ldap_unbind);
                        g_rec_mutex_unlock (&eds_ldap_handler_lock);
                        g_propagate_error (error,
                                e_client_error_create (E_CLIENT_ERROR_OTHER_ERROR, _("Failed to bind using 
either v3 or v2 binds")));
@@ -879,19 +876,13 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl,
                } else if (ldap_error == LDAP_SERVER_DOWN) {
                        /* we only want this to be fatal if the server is down. */
                        g_warning ("failed to bind anonymously while connecting (ldap_error 0x%02x)", 
ldap_error);
-                       if (blpriv->ldap) {
-                               ldap_unbind (blpriv->ldap);
-                               blpriv->ldap = NULL;
-                       }
+                       g_clear_pointer (&blpriv->ldap, ldap_unbind);
                        g_rec_mutex_unlock (&eds_ldap_handler_lock);
                        g_propagate_error (error, EC_ERROR (E_CLIENT_ERROR_REPOSITORY_OFFLINE));
                        return FALSE;
                } else if (ldap_error == LDAP_INVALID_CREDENTIALS) {
                        g_warning ("Invalid credentials while connecting (ldap_error 0x%02x)", ldap_error);
-                       if (blpriv->ldap) {
-                               ldap_unbind (blpriv->ldap);
-                               blpriv->ldap = NULL;
-                       }
+                       g_clear_pointer (&blpriv->ldap, ldap_unbind);
                        g_rec_mutex_unlock (&eds_ldap_handler_lock);
                        g_propagate_error (error, EC_ERROR (E_CLIENT_ERROR_AUTHENTICATION_FAILED));
                        return FALSE;
@@ -935,26 +926,17 @@ e_book_backend_ldap_connect (EBookBackendLDAP *bl,
                        e_backend_ensure_source_status_connected (E_BACKEND (bl));
                        return TRUE;
                } else if (ldap_error == LDAP_UNWILLING_TO_PERFORM) {
-                       if (blpriv->ldap) {
-                               ldap_unbind (blpriv->ldap);
-                               blpriv->ldap = NULL;
-                       }
+                       g_clear_pointer (&blpriv->ldap, ldap_unbind);
                        g_rec_mutex_unlock (&eds_ldap_handler_lock);
                        g_propagate_error (error, EC_ERROR (E_CLIENT_ERROR_AUTHENTICATION_FAILED));
                        return FALSE;
                } else {
-                       if (blpriv->ldap) {
-                               ldap_unbind (blpriv->ldap);
-                               blpriv->ldap = NULL;
-                       }
+                       g_clear_pointer (&blpriv->ldap, ldap_unbind);
                        g_rec_mutex_unlock (&eds_ldap_handler_lock);
                        g_warning ("Failed to perform root dse query anonymously, (ldap_error 0x%02x)", 
ldap_error);
                }
        } else {
-               if (blpriv->ldap) {
-                       ldap_unbind (blpriv->ldap);
-                       blpriv->ldap = NULL;
-               }
+               g_clear_pointer (&blpriv->ldap, ldap_unbind);
                g_rec_mutex_unlock (&eds_ldap_handler_lock);
        }
 
@@ -4962,10 +4944,7 @@ book_backend_ldap_finalize (GObject *object)
                priv->summary = NULL;
        }
 
-       if (priv->cache) {
-               g_object_unref (priv->cache);
-               priv->cache = NULL;
-       }
+       g_clear_object (&priv->cache);
 
        g_free (priv->ldap_host);
        g_free (priv->ldap_rootdn);
@@ -5084,10 +5063,7 @@ book_backend_ldap_open (EBookBackend *backend,
                        g_warn_if_reached ();
        }
 
-       if (bl->priv->cache) {
-               g_object_unref (bl->priv->cache);
-               bl->priv->cache = NULL;
-       }
+       g_clear_object (&bl->priv->cache);
 
        filename = g_build_filename (cache_dir, "cache.xml", NULL);
        bl->priv->cache = e_book_backend_cache_new (filename);
diff --git a/src/addressbook/libebook/e-book-client-view.c b/src/addressbook/libebook/e-book-client-view.c
index 07648b61a..368d33dcf 100644
--- a/src/addressbook/libebook/e-book-client-view.c
+++ b/src/addressbook/libebook/e-book-client-view.c
@@ -786,21 +786,9 @@ book_client_view_dispose (GObject *object)
        priv = E_BOOK_CLIENT_VIEW (object)->priv;
 
        g_clear_object (&priv->client);
-
-       if (priv->connection != NULL) {
-               g_object_unref (priv->connection);
-               priv->connection = NULL;
-       }
-
-       if (priv->main_context != NULL) {
-               g_main_context_unref (priv->main_context);
-               priv->main_context = NULL;
-       }
-
-       if (priv->direct_backend != NULL) {
-               g_object_unref (priv->direct_backend);
-               priv->direct_backend = NULL;
-       }
+       g_clear_object (&priv->connection);
+       g_clear_pointer (&priv->main_context, g_main_context_unref);
+       g_clear_object (&priv->direct_backend);
 
        if (priv->dbus_proxy != NULL) {
                g_signal_handler_disconnect (
diff --git a/src/addressbook/libebook/e-book-client.c b/src/addressbook/libebook/e-book-client.c
index ad90e5eea..709bc52fd 100644
--- a/src/addressbook/libebook/e-book-client.c
+++ b/src/addressbook/libebook/e-book-client.c
@@ -747,10 +747,7 @@ book_client_dispose (GObject *object)
                priv->dbus_proxy = NULL;
        }
 
-       if (priv->direct_backend != NULL) {
-               g_object_unref (priv->direct_backend);
-               priv->direct_backend = NULL;
-       }
+       g_clear_object (&priv->direct_backend);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_book_client_parent_class)->dispose (object);
diff --git a/src/addressbook/libebook/e-book-view.c b/src/addressbook/libebook/e-book-view.c
index 7fedca25f..3366b34a0 100644
--- a/src/addressbook/libebook/e-book-view.c
+++ b/src/addressbook/libebook/e-book-view.c
@@ -153,11 +153,7 @@ book_view_dispose (GObject *object)
        EBookViewPrivate *priv;
 
        priv = E_BOOK_VIEW (object)->priv;
-
-       if (priv->book != NULL) {
-               g_object_unref (priv->book);
-               priv->book = NULL;
-       }
+       g_clear_object (&priv->book);
 
        if (priv->client_view != NULL) {
                g_signal_handler_disconnect (
diff --git a/src/addressbook/libebook/e-book.c b/src/addressbook/libebook/e-book.c
index ed23af884..a3eb28f09 100644
--- a/src/addressbook/libebook/e-book.c
+++ b/src/addressbook/libebook/e-book.c
@@ -177,10 +177,7 @@ book_dispose (GObject *object)
                priv->client = NULL;
        }
 
-       if (priv->source != NULL) {
-               g_object_unref (priv->source);
-               priv->source = NULL;
-       }
+       g_clear_object (&priv->source);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_book_parent_class)->dispose (object);
diff --git a/src/addressbook/libebook/e-destination.c b/src/addressbook/libebook/e-destination.c
index 352b2fb6b..94b1d1b33 100644
--- a/src/addressbook/libebook/e-destination.c
+++ b/src/addressbook/libebook/e-destination.c
@@ -236,10 +236,7 @@ e_destination_clear (EDestination *dest)
        g_free (dest->priv->textrep);
        dest->priv->textrep = NULL;
 
-       if (dest->priv->contact) {
-               g_object_unref (dest->priv->contact);
-               dest->priv->contact = NULL;
-       }
+       g_clear_object (&dest->priv->contact);
        dest->priv->email_num = -1;
 
        g_list_foreach (dest->priv->list_dests, (GFunc) g_object_unref, NULL);
@@ -1065,11 +1062,7 @@ e_destination_get_address (const EDestination *dest)
        g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
 
        priv = (EDestinationPrivate *) dest->priv; /* cast out const */
-
-       if (priv->addr) {
-               g_free (priv->addr);
-               priv->addr = NULL;
-       }
+       g_clear_pointer (&priv->addr, g_free);
 
        if (e_destination_is_evolution_list (dest)) {
                destination_get_address (dest, addr);
diff --git a/src/addressbook/libedata-book/e-book-backend-sqlitedb.c 
b/src/addressbook/libedata-book/e-book-backend-sqlitedb.c
index 681cb893e..5672a4190 100644
--- a/src/addressbook/libedata-book/e-book-backend-sqlitedb.c
+++ b/src/addressbook/libedata-book/e-book-backend-sqlitedb.c
@@ -323,10 +323,7 @@ book_backend_sql_exec_real (sqlite3 *db,
                        break;
                retries++;
 
-               if (errmsg) {
-                       sqlite3_free (errmsg);
-                       errmsg = NULL;
-               }
+               g_clear_pointer (&errmsg, sqlite3_free);
                g_thread_yield ();
                g_usleep (100 * 1000); /* Sleep for 100 ms */
 
@@ -345,10 +342,7 @@ book_backend_sql_exec_real (sqlite3 *db,
                return FALSE;
        }
 
-       if (errmsg) {
-               sqlite3_free (errmsg);
-               errmsg = NULL;
-       }
+       g_clear_pointer (&errmsg, sqlite3_free);
 
        return TRUE;
 }
diff --git a/src/addressbook/libedata-book/e-book-cache.c b/src/addressbook/libedata-book/e-book-cache.c
index 01877edd3..abe06d20f 100644
--- a/src/addressbook/libedata-book/e-book-cache.c
+++ b/src/addressbook/libedata-book/e-book-cache.c
@@ -6337,10 +6337,7 @@ e_book_cache_finalize (GObject *object)
 
        g_clear_object (&book_cache->priv->source);
 
-       if (book_cache->priv->collator) {
-               e_collator_unref (book_cache->priv->collator);
-               book_cache->priv->collator = NULL;
-       }
+       g_clear_pointer (&book_cache->priv->collator, e_collator_unref);
 
        g_free (book_cache->priv->locale);
        g_free (book_cache->priv->region_code);
diff --git a/src/addressbook/libedata-book/e-book-sqlite.c b/src/addressbook/libedata-book/e-book-sqlite.c
index 82817ded5..828bfe2de 100644
--- a/src/addressbook/libedata-book/e-book-sqlite.c
+++ b/src/addressbook/libedata-book/e-book-sqlite.c
@@ -1163,10 +1163,7 @@ ebsql_exec (EBookSqlite *ebsql,
                        break;
                retries++;
 
-               if (errmsg) {
-                       sqlite3_free (errmsg);
-                       errmsg = NULL;
-               }
+               g_clear_pointer (&errmsg, sqlite3_free);
                g_thread_yield ();
                g_usleep (100 * 1000); /* Sleep for 100 ms */
 
diff --git a/src/addressbook/libedata-book/e-data-book-view.c 
b/src/addressbook/libedata-book/e-data-book-view.c
index 965f99f7e..462a995c5 100644
--- a/src/addressbook/libedata-book/e-data-book-view.c
+++ b/src/addressbook/libedata-book/e-data-book-view.c
@@ -344,10 +344,7 @@ impl_DataBookView_set_fields_of_interest (EDBusAddressBookView *object,
 
        g_return_val_if_fail (in_fields_of_interest != NULL, TRUE);
 
-       if (view->priv->fields_of_interest != NULL) {
-               g_hash_table_destroy (view->priv->fields_of_interest);
-               view->priv->fields_of_interest = NULL;
-       }
+       g_clear_pointer (&view->priv->fields_of_interest, g_hash_table_destroy);
 
        view->priv->send_uids_only = FALSE;
 
diff --git a/src/addressbook/libedata-book/e-data-book.c b/src/addressbook/libedata-book/e-data-book.c
index 825514229..1e413c4aa 100644
--- a/src/addressbook/libedata-book/e-data-book.c
+++ b/src/addressbook/libedata-book/e-data-book.c
@@ -1676,15 +1676,8 @@ data_book_dispose (GObject *object)
 
        g_weak_ref_set (&priv->backend, NULL);
 
-       if (priv->connection != NULL) {
-               g_object_unref (priv->connection);
-               priv->connection = NULL;
-       }
-
-       if (priv->direct_book) {
-               g_object_unref (priv->direct_book);
-               priv->direct_book = NULL;
-       }
+       g_clear_object (&priv->connection);
+       g_clear_object (&priv->direct_book);
 
        if (priv->direct_module) {
                g_type_module_unuse (G_TYPE_MODULE (priv->direct_module));
@@ -1710,10 +1703,7 @@ data_book_finalize (GObject *object)
        g_weak_ref_clear (&priv->backend);
        g_hash_table_destroy (priv->sender_table);
 
-       if (priv->dbus_interface) {
-               g_object_unref (priv->dbus_interface);
-               priv->dbus_interface = NULL;
-       }
+       g_clear_object (&priv->dbus_interface);
 
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_data_book_parent_class)->finalize (object);
diff --git a/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c 
b/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
index 5cba2b650..3897042e6 100644
--- a/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
+++ b/src/addressbook/libedata-book/evolution-addressbook-factory-subprocess.c
@@ -55,10 +55,7 @@ prepare_shutdown_and_quit (ESubprocessBookFactory *subprocess_book_factory,
 {
        e_subprocess_factory_call_backends_prepare_shutdown (E_SUBPROCESS_FACTORY (subprocess_book_factory));
 
-       if (sd->loop) {
-               g_main_loop_quit (sd->loop);
-               sd->loop = NULL;
-       }
+       g_clear_pointer (&sd->loop, g_main_loop_quit);
 }
 
 static gboolean
diff --git a/src/calendar/backends/file/e-cal-backend-file.c b/src/calendar/backends/file/e-cal-backend-file.c
index 79d8b1a8e..d05bbf9f2 100644
--- a/src/calendar/backends/file/e-cal-backend-file.c
+++ b/src/calendar/backends/file/e-cal-backend-file.c
@@ -1124,9 +1124,7 @@ free_refresh_data (ECalBackendFile *cbfile)
 
        g_mutex_lock (&priv->refresh_lock);
 
-       if (priv->refresh_monitor)
-               g_object_unref (priv->refresh_monitor);
-       priv->refresh_monitor = NULL;
+       g_clear_object (&priv->refresh_monitor);
 
        if (priv->refresh_cond) {
                priv->refresh_thread_stop = TRUE;
@@ -3947,9 +3945,7 @@ e_cal_backend_file_set_file_name (ECalBackendFile *cbfile,
        priv = cbfile->priv;
        g_rec_mutex_lock (&priv->idle_save_rmutex);
 
-       if (priv->file_name)
-               g_free (priv->file_name);
-
+       g_free (priv->file_name);
        priv->file_name = g_strdup (file_name);
 
        g_rec_mutex_unlock (&priv->idle_save_rmutex);
diff --git a/src/calendar/backends/http/e-cal-backend-http.c b/src/calendar/backends/http/e-cal-backend-http.c
index 96ca1f340..a7e930ca0 100644
--- a/src/calendar/backends/http/e-cal-backend-http.c
+++ b/src/calendar/backends/http/e-cal-backend-http.c
@@ -355,10 +355,7 @@ ecb_http_disconnect_sync (ECalMetaBackend *meta_backend,
        if (cbhttp->priv->session)
                soup_session_abort (SOUP_SESSION (cbhttp->priv->session));
 
-       if (cbhttp->priv->components) {
-               g_hash_table_destroy (cbhttp->priv->components);
-               cbhttp->priv->components = NULL;
-       }
+       g_clear_pointer (&cbhttp->priv->components, g_hash_table_destroy);
 
        g_rec_mutex_unlock (&cbhttp->priv->conn_lock);
 
@@ -704,10 +701,7 @@ e_cal_backend_http_dispose (GObject *object)
        if (cbhttp->priv->session)
                soup_session_abort (SOUP_SESSION (cbhttp->priv->session));
 
-       if (cbhttp->priv->components) {
-               g_hash_table_destroy (cbhttp->priv->components);
-               cbhttp->priv->components = NULL;
-       }
+       g_clear_pointer (&cbhttp->priv->components, g_hash_table_destroy);
 
        g_rec_mutex_unlock (&cbhttp->priv->conn_lock);
 
diff --git a/src/calendar/backends/weather/e-weather-source.c 
b/src/calendar/backends/weather/e-weather-source.c
index 7a35d6fee..dee8a4d77 100644
--- a/src/calendar/backends/weather/e-weather-source.c
+++ b/src/calendar/backends/weather/e-weather-source.c
@@ -39,11 +39,7 @@ weather_source_dispose (GObject *object)
        EWeatherSourcePrivate *priv;
 
        priv = E_WEATHER_SOURCE (object)->priv;
-
-       if (priv->location != NULL) {
-               gweather_location_unref (priv->location);
-               priv->location = NULL;
-       }
+       g_clear_pointer (&priv->location, gweather_location_unref);
 
        g_clear_object (&priv->info);
 
diff --git a/src/calendar/libecal/e-cal-client-view.c b/src/calendar/libecal/e-cal-client-view.c
index fde688174..b629a089d 100644
--- a/src/calendar/libecal/e-cal-client-view.c
+++ b/src/calendar/libecal/e-cal-client-view.c
@@ -597,16 +597,8 @@ cal_client_view_dispose (GObject *object)
        priv = E_CAL_CLIENT_VIEW (object)->priv;
 
        g_clear_object (&priv->client);
-
-       if (priv->connection != NULL) {
-               g_object_unref (priv->connection);
-               priv->connection = NULL;
-       }
-
-       if (priv->main_context != NULL) {
-               g_main_context_unref (priv->main_context);
-               priv->main_context = NULL;
-       }
+       g_clear_object (&priv->connection);
+       g_clear_pointer (&priv->main_context, g_main_context_unref);
 
        if (priv->dbus_proxy != NULL) {
                g_signal_handler_disconnect (
diff --git a/src/calendar/libecal/e-reminder-watcher.c b/src/calendar/libecal/e-reminder-watcher.c
index 50342ee78..f33aff4c7 100644
--- a/src/calendar/libecal/e-reminder-watcher.c
+++ b/src/calendar/libecal/e-reminder-watcher.c
@@ -2151,10 +2151,7 @@ e_reminder_watcher_dispose (GObject *object)
        g_slist_free_full (watcher->priv->snoozed, e_reminder_data_free);
        watcher->priv->snoozed = NULL;
 
-       if (watcher->priv->scheduled) {
-               g_hash_table_destroy (watcher->priv->scheduled);
-               watcher->priv->scheduled = NULL;
-       }
+       g_clear_pointer (&watcher->priv->scheduled, g_hash_table_destroy);
 
        if (watcher->priv->settings && watcher->priv->past_changed_handler_id) {
                g_signal_handler_disconnect (watcher->priv->settings, watcher->priv->past_changed_handler_id);
diff --git a/src/calendar/libedata-cal/e-data-cal-view.c b/src/calendar/libedata-cal/e-data-cal-view.c
index 93bd68308..3398600c9 100644
--- a/src/calendar/libedata-cal/e-data-cal-view.c
+++ b/src/calendar/libedata-cal/e-data-cal-view.c
@@ -288,10 +288,7 @@ impl_DataCalView_set_fields_of_interest (EDBusCalendarView *object,
 
        g_return_val_if_fail (in_fields_of_interest != NULL, TRUE);
 
-       if (view->priv->fields_of_interest != NULL) {
-               g_hash_table_destroy (view->priv->fields_of_interest);
-               view->priv->fields_of_interest = NULL;
-       }
+       g_clear_pointer (&view->priv->fields_of_interest, g_hash_table_destroy);
 
        for (ii = 0; in_fields_of_interest[ii]; ii++) {
                const gchar *field = in_fields_of_interest[ii];
diff --git a/src/calendar/libedata-cal/e-data-cal.c b/src/calendar/libedata-cal/e-data-cal.c
index c68e135b6..bdb9299a2 100644
--- a/src/calendar/libedata-cal/e-data-cal.c
+++ b/src/calendar/libedata-cal/e-data-cal.c
@@ -2285,10 +2285,7 @@ data_cal_dispose (GObject *object)
 
        g_weak_ref_set (&priv->backend, NULL);
 
-       if (priv->connection != NULL) {
-               g_object_unref (priv->connection);
-               priv->connection = NULL;
-       }
+       g_clear_object (&priv->connection);
 
        g_hash_table_remove_all (priv->sender_table);
 
@@ -2309,10 +2306,7 @@ data_cal_finalize (GObject *object)
        g_weak_ref_clear (&priv->backend);
        g_hash_table_destroy (priv->sender_table);
 
-       if (priv->dbus_interface) {
-               g_object_unref (priv->dbus_interface);
-               priv->dbus_interface = NULL;
-       }
+       g_clear_object (&priv->dbus_interface);
 
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_data_cal_parent_class)->finalize (object);
diff --git a/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c 
b/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
index f59a76c95..29732fc6e 100644
--- a/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
+++ b/src/calendar/libedata-cal/evolution-calendar-factory-subprocess.c
@@ -55,10 +55,7 @@ prepare_shutdown_and_quit (ESubprocessCalFactory *subprocess_cal_factory,
 {
        e_subprocess_factory_call_backends_prepare_shutdown (E_SUBPROCESS_FACTORY (subprocess_cal_factory));
 
-       if (sd->loop) {
-               g_main_loop_quit (sd->loop);
-               sd->loop = NULL;
-       }
+       g_clear_pointer (&sd->loop, g_main_loop_quit);
 }
 
 static gboolean
diff --git a/src/camel/camel-certdb.c b/src/camel/camel-certdb.c
index 8079b671d..0e4db2456 100644
--- a/src/camel/camel-certdb.c
+++ b/src/camel/camel-certdb.c
@@ -337,10 +337,7 @@ camel_cert_load_cert_file (CamelCert *cert,
 
        g_return_val_if_fail (cert != NULL, FALSE);
 
-       if (cert->rawcert) {
-               g_bytes_unref (cert->rawcert);
-               cert->rawcert = NULL;
-       }
+       g_clear_pointer (&cert->rawcert, g_bytes_unref);
 
        cert_dir = certdb_get_cert_dir ();
        filename = g_build_filename (cert_dir, cert->fingerprint, NULL);
@@ -366,10 +363,7 @@ camel_cert_save_cert_file (CamelCert *cert,
        g_return_val_if_fail (cert != NULL, FALSE);
        g_return_val_if_fail (der_data != NULL, FALSE);
 
-       if (cert->rawcert) {
-               g_bytes_unref (cert->rawcert);
-               cert->rawcert = NULL;
-       }
+       g_clear_pointer (&cert->rawcert, g_bytes_unref);
 
        cert_dir = certdb_get_cert_dir ();
        filename = g_build_filename (cert_dir, cert->fingerprint, NULL);
diff --git a/src/camel/camel-cipher-context.c b/src/camel/camel-cipher-context.c
index 78ef41b8f..0664204cf 100644
--- a/src/camel/camel-cipher-context.c
+++ b/src/camel/camel-cipher-context.c
@@ -147,11 +147,7 @@ cipher_context_dispose (GObject *object)
        CamelCipherContextPrivate *priv;
 
        priv = CAMEL_CIPHER_CONTEXT (object)->priv;
-
-       if (priv->session != NULL) {
-               g_object_unref (priv->session);
-               priv->session = NULL;
-       }
+       g_clear_object (&priv->session);
 
        /* Chain up to parent's dispose () method. */
        G_OBJECT_CLASS (camel_cipher_context_parent_class)->dispose (object);
diff --git a/src/camel/camel-data-wrapper.c b/src/camel/camel-data-wrapper.c
index 924cd30d1..c6698d682 100644
--- a/src/camel/camel-data-wrapper.c
+++ b/src/camel/camel-data-wrapper.c
@@ -69,10 +69,7 @@ data_wrapper_dispose (GObject *object)
 {
        CamelDataWrapper *data_wrapper = CAMEL_DATA_WRAPPER (object);
 
-       if (data_wrapper->priv->mime_type != NULL) {
-               camel_content_type_unref (data_wrapper->priv->mime_type);
-               data_wrapper->priv->mime_type = NULL;
-       }
+       g_clear_pointer (&data_wrapper->priv->mime_type, camel_content_type_unref);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_data_wrapper_parent_class)->dispose (object);
diff --git a/src/camel/camel-db.c b/src/camel/camel-db.c
index 154b2a70f..8ae4870bc 100644
--- a/src/camel/camel-db.c
+++ b/src/camel/camel-db.c
@@ -564,10 +564,7 @@ cdb_sql_exec (sqlite3 *db,
                        break;
                retries++;
 
-               if (errmsg) {
-                       sqlite3_free (errmsg);
-                       errmsg = NULL;
-               }
+               g_clear_pointer (&errmsg, sqlite3_free);
                g_thread_yield ();
                g_usleep (100 * 1000); /* Sleep for 100 ms */
 
@@ -587,10 +584,7 @@ cdb_sql_exec (sqlite3 *db,
                return -1;
        }
 
-       if (errmsg) {
-               sqlite3_free (errmsg);
-               errmsg = NULL;
-       }
+       g_clear_pointer (&errmsg, sqlite3_free);
 
        return 0;
 }
diff --git a/src/camel/camel-debug.c b/src/camel/camel-debug.c
index 6f93a41a5..10be94602 100644
--- a/src/camel/camel-debug.c
+++ b/src/camel/camel-debug.c
@@ -649,10 +649,7 @@ dump_left_at_exit_cb (void)
        dump_tracked_ptrs (TRUE);
 
        G_LOCK (ptr_tracker);
-       if (ptr_tracker) {
-               g_hash_table_destroy (ptr_tracker);
-               ptr_tracker = NULL;
-       }
+       g_clear_pointer (&ptr_tracker, g_hash_table_destroy);
        G_UNLOCK (ptr_tracker);
 }
 
diff --git a/src/camel/camel-filter-driver.c b/src/camel/camel-filter-driver.c
index b79b7210b..74b7829ad 100644
--- a/src/camel/camel-filter-driver.c
+++ b/src/camel/camel-filter-driver.c
@@ -340,11 +340,7 @@ filter_driver_dispose (GObject *object)
        CamelFilterDriverPrivate *priv;
 
        priv = CAMEL_FILTER_DRIVER (object)->priv;
-
-       if (priv->transfers) {
-               g_hash_table_destroy (priv->transfers);
-               priv->transfers = NULL;
-       }
+       g_clear_pointer (&priv->transfers, g_hash_table_destroy);
 
        g_slist_free_full (priv->delete_after_transfer, g_object_unref);
        priv->delete_after_transfer = NULL;
@@ -355,10 +351,7 @@ filter_driver_dispose (GObject *object)
                priv->defaultfolder = NULL;
        }
 
-       if (priv->session != NULL) {
-               g_object_unref (priv->session);
-               priv->session = NULL;
-       }
+       g_clear_object (&priv->session);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_filter_driver_parent_class)->dispose (object);
@@ -1636,10 +1629,7 @@ camel_filter_driver_filter_mbox (CamelFilterDriver *driver,
        }
        fd = -1;
 
-       if (driver->priv->transfers) {
-               g_hash_table_destroy (driver->priv->transfers);
-               driver->priv->transfers = NULL;
-       }
+       g_clear_pointer (&driver->priv->transfers, g_hash_table_destroy);
 
        g_slist_free_full (driver->priv->delete_after_transfer, g_object_unref);
        driver->priv->delete_after_transfer = NULL;
@@ -1783,10 +1773,7 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver,
                freeuids = TRUE;
        }
 
-       if (driver->priv->transfers) {
-               g_hash_table_destroy (driver->priv->transfers);
-               driver->priv->transfers = NULL;
-       }
+       g_clear_pointer (&driver->priv->transfers, g_hash_table_destroy);
 
        g_slist_free_full (driver->priv->delete_after_transfer, g_object_unref);
        driver->priv->delete_after_transfer = NULL;
@@ -1956,10 +1943,7 @@ filter_driver_filter_message_internal (CamelFilterDriver *driver,
        }
 
        if (can_process_transfers) {
-               if (driver->priv->transfers) {
-                       g_hash_table_destroy (driver->priv->transfers);
-                       driver->priv->transfers = NULL;
-               }
+               g_clear_pointer (&driver->priv->transfers, g_hash_table_destroy);
 
                g_slist_free_full (driver->priv->delete_after_transfer, g_object_unref);
                driver->priv->delete_after_transfer = NULL;
diff --git a/src/camel/camel-folder.c b/src/camel/camel-folder.c
index a0e7c5c9e..9298e5674 100644
--- a/src/camel/camel-folder.c
+++ b/src/camel/camel-folder.c
@@ -139,8 +139,7 @@ async_context_free (AsyncContext *async_context)
        if (async_context->message != NULL)
                g_object_unref (async_context->message);
 
-       if (async_context->info != NULL)
-               g_clear_object (&async_context->info);
+       g_clear_object (&async_context->info);
 
        if (async_context->destination != NULL)
                g_object_unref (async_context->destination);
@@ -5122,10 +5121,7 @@ camel_folder_change_info_clear (CamelFolderChangeInfo *info)
        g_ptr_array_set_size (info->uid_removed, 0);
        g_ptr_array_set_size (info->uid_changed, 0);
        g_ptr_array_set_size (info->uid_recent, 0);
-       if (p->uid_source) {
-               g_hash_table_destroy (p->uid_source);
-               p->uid_source = NULL;
-       }
+       g_clear_pointer (&p->uid_source, g_hash_table_destroy);
        g_hash_table_destroy (p->uid_stored);
        p->uid_stored = g_hash_table_new (g_str_hash, g_str_equal);
        g_ptr_array_set_size (p->uid_filter, 0);
diff --git a/src/camel/camel-index.c b/src/camel/camel-index.c
index b7b2708ba..5447b29f0 100644
--- a/src/camel/camel-index.c
+++ b/src/camel/camel-index.c
@@ -367,10 +367,7 @@ index_name_dispose (GObject *object)
 {
        CamelIndexName *index_name = CAMEL_INDEX_NAME (object);
 
-       if (index_name->index != NULL) {
-               g_object_unref (index_name->index);
-               index_name->index = NULL;
-       }
+       g_clear_object (&index_name->index);
 
        /* Chain up to parent's dispose () method. */
        G_OBJECT_CLASS (camel_index_name_parent_class)->dispose (object);
@@ -439,10 +436,7 @@ index_cursor_dispose (GObject *object)
 {
        CamelIndexCursor *index_cursor = CAMEL_INDEX_CURSOR (object);
 
-       if (index_cursor->index != NULL) {
-               g_object_unref (index_cursor->index);
-               index_cursor->index = NULL;
-       }
+       g_clear_object (&index_cursor->index);
 
        /* Chain up to parent's dispose () method. */
        G_OBJECT_CLASS (camel_index_cursor_parent_class)->dispose (object);
diff --git a/src/camel/camel-medium.c b/src/camel/camel-medium.c
index 9973cedfe..799b07527 100644
--- a/src/camel/camel-medium.c
+++ b/src/camel/camel-medium.c
@@ -82,11 +82,7 @@ medium_dispose (GObject *object)
        CamelMediumPrivate *priv;
 
        priv = CAMEL_MEDIUM (object)->priv;
-
-       if (priv->content != NULL) {
-               g_object_unref (priv->content);
-               priv->content = NULL;
-       }
+       g_clear_object (&priv->content);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_medium_parent_class)->dispose (object);
diff --git a/src/camel/camel-message-info-base.c b/src/camel/camel-message-info-base.c
index a77e9700a..dac7834ee 100644
--- a/src/camel/camel-message-info-base.c
+++ b/src/camel/camel-message-info-base.c
@@ -805,10 +805,7 @@ message_info_base_dispose (GObject *object)
        g_clear_pointer (&bmi->priv->cc, (GDestroyNotify) camel_pstring_free);
        g_clear_pointer (&bmi->priv->mlist, (GDestroyNotify) camel_pstring_free);
 
-       if (bmi->priv->references) {
-               g_array_unref (bmi->priv->references);
-               bmi->priv->references = NULL;
-       }
+       g_clear_pointer (&bmi->priv->references, g_array_unref);
 
        camel_name_value_array_free (bmi->priv->headers);
        bmi->priv->headers = NULL;
diff --git a/src/camel/camel-mime-filter-html.c b/src/camel/camel-mime-filter-html.c
index 15b880aec..7074be2f1 100644
--- a/src/camel/camel-mime-filter-html.c
+++ b/src/camel/camel-mime-filter-html.c
@@ -119,11 +119,7 @@ mime_filter_html_dispose (GObject *object)
        CamelMimeFilterHTMLPrivate *priv;
 
        priv = CAMEL_MIME_FILTER_HTML (object)->priv;
-
-       if (priv->ctxt != NULL) {
-               g_object_unref (priv->ctxt);
-               priv->ctxt = NULL;
-       }
+       g_clear_object (&priv->ctxt);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_mime_filter_html_parent_class)->dispose (object);
diff --git a/src/camel/camel-mime-filter-index.c b/src/camel/camel-mime-filter-index.c
index 4b823efa0..35c07c743 100644
--- a/src/camel/camel-mime-filter-index.c
+++ b/src/camel/camel-mime-filter-index.c
@@ -32,16 +32,8 @@ mime_filter_index_dispose (GObject *object)
        CamelMimeFilterIndexPrivate *priv;
 
        priv = CAMEL_MIME_FILTER_INDEX (object)->priv;
-
-       if (priv->name != NULL) {
-               g_object_unref (priv->name);
-               priv->name = NULL;
-       }
-
-       if (priv->index != NULL) {
-               g_object_unref (priv->index);
-               priv->index = NULL;
-       }
+       g_clear_object (&priv->name);
+       g_clear_object (&priv->index);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_mime_filter_index_parent_class)->dispose (object);
diff --git a/src/camel/camel-mime-filter-progress.c b/src/camel/camel-mime-filter-progress.c
index 16f853d14..e265ecf90 100644
--- a/src/camel/camel-mime-filter-progress.c
+++ b/src/camel/camel-mime-filter-progress.c
@@ -42,11 +42,7 @@ mime_filter_progress_dispose (GObject *object)
        CamelMimeFilterProgressPrivate *priv;
 
        priv = CAMEL_MIME_FILTER_PROGRESS (object)->priv;
-
-       if (priv->cancellable != NULL) {
-               g_object_unref (priv->cancellable);
-               priv->cancellable = NULL;
-       }
+       g_clear_object (&priv->cancellable);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_mime_filter_progress_parent_class)->dispose (object);
diff --git a/src/camel/camel-sasl-ntlm.c b/src/camel/camel-sasl-ntlm.c
index 0fe72cfac..32fa3a4a8 100644
--- a/src/camel/camel-sasl-ntlm.c
+++ b/src/camel/camel-sasl-ntlm.c
@@ -971,8 +971,7 @@ sasl_ntlm_finalize (GObject *object)
        CamelSaslNTLM *ntlm = CAMEL_SASL_NTLM (object);
        CamelSaslNTLMPrivate *priv = ntlm->priv;
 
-       if (priv->type1_msg)
-               g_free (priv->type1_msg);
+       g_free (priv->type1_msg);
        if (priv->helper_stream)
                g_object_unref (priv->helper_stream);
 #endif
diff --git a/src/camel/camel-sasl.c b/src/camel/camel-sasl.c
index c532f0dbe..a824f9412 100644
--- a/src/camel/camel-sasl.c
+++ b/src/camel/camel-sasl.c
@@ -250,11 +250,7 @@ sasl_dispose (GObject *object)
        CamelSaslPrivate *priv;
 
        priv = CAMEL_SASL (object)->priv;
-
-       if (priv->service != NULL) {
-               g_object_unref (priv->service);
-               priv->service = NULL;
-       }
+       g_clear_object (&priv->service);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_sasl_parent_class)->dispose (object);
diff --git a/src/camel/camel-sexp.c b/src/camel/camel-sexp.c
index 50c263ade..ffe1819e9 100644
--- a/src/camel/camel-sexp.c
+++ b/src/camel/camel-sexp.c
@@ -183,8 +183,7 @@ camel_sexp_fatal_error (CamelSExp *sexp,
        /* jumps back to the caller of sexp->priv->failenv,
         * only to be called from inside a callback */
 
-       if (sexp->priv->error)
-               g_free (sexp->priv->error);
+       g_free (sexp->priv->error);
 
        va_start (args, why);
        sexp->priv->error = g_strdup_vprintf (why, args);
diff --git a/src/camel/camel-store.c b/src/camel/camel-store.c
index 5c0ecfc21..71c4ea7f4 100644
--- a/src/camel/camel-store.c
+++ b/src/camel/camel-store.c
@@ -101,10 +101,7 @@ G_DEFINE_BOXED_TYPE (CamelFolderInfo,
 static void
 async_context_free (AsyncContext *async_context)
 {
-       if (async_context->save_setup) {
-               g_hash_table_destroy (async_context->save_setup);
-               async_context->save_setup = NULL;
-       }
+       g_clear_pointer (&async_context->save_setup, g_hash_table_destroy);
 
        g_free (async_context->folder_name_1);
        g_free (async_context->folder_name_2);
@@ -337,10 +334,7 @@ store_dispose (GObject *object)
 {
        CamelStore *store = CAMEL_STORE (object);
 
-       if (store->priv->folders) {
-               camel_object_bag_destroy (store->priv->folders);
-               store->priv->folders = NULL;
-       }
+       g_clear_pointer (&store->priv->folders, camel_object_bag_destroy);
 
        /* Chain up to parent's method. */
        G_OBJECT_CLASS (camel_store_parent_class)->dispose (object);
diff --git a/src/camel/camel-stream-buffer.c b/src/camel/camel-stream-buffer.c
index 0c78596d7..6a83a78a9 100644
--- a/src/camel/camel-stream-buffer.c
+++ b/src/camel/camel-stream-buffer.c
@@ -90,11 +90,7 @@ stream_buffer_dispose (GObject *object)
        CamelStreamBufferPrivate *priv;
 
        priv = CAMEL_STREAM_BUFFER (object)->priv;
-
-       if (priv->stream != NULL) {
-               g_object_unref (priv->stream);
-               priv->stream = NULL;
-       }
+       g_clear_object (&priv->stream);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_stream_buffer_parent_class)->dispose (object);
diff --git a/src/camel/camel-text-index.c b/src/camel/camel-text-index.c
index 7987e0028..7187646d8 100644
--- a/src/camel/camel-text-index.c
+++ b/src/camel/camel-text-index.c
@@ -156,35 +156,12 @@ text_index_dispose (GObject *object)
        if (priv->word_index != NULL)
                camel_index_sync (CAMEL_INDEX (object));
 
-       if (priv->word_index != NULL) {
-               g_object_unref (priv->word_index);
-               priv->word_index = NULL;
-       }
-
-       if (priv->word_hash != NULL) {
-               g_object_unref (priv->word_hash);
-               priv->word_hash = NULL;
-       }
-
-       if (priv->name_index != NULL) {
-               g_object_unref (priv->name_index);
-               priv->name_index = NULL;
-       }
-
-       if (priv->name_hash != NULL) {
-               g_object_unref (priv->name_hash);
-               priv->name_hash = NULL;
-       }
-
-       if (priv->blocks != NULL) {
-               g_object_unref (priv->blocks);
-               priv->blocks = NULL;
-       }
-
-       if (priv->links != NULL) {
-               g_object_unref (priv->links);
-               priv->links = NULL;
-       }
+       g_clear_object (&priv->word_index);
+       g_clear_object (&priv->word_hash);
+       g_clear_object (&priv->name_index);
+       g_clear_object (&priv->name_hash);
+       g_clear_object (&priv->blocks);
+       g_clear_object (&priv->links);
 
        /* Chain up to parent's dispose () method. */
        G_OBJECT_CLASS (camel_text_index_parent_class)->dispose (object);
@@ -1736,11 +1713,7 @@ text_index_key_cursor_dispose (GObject *object)
        CamelTextIndexKeyCursorPrivate *priv;
 
        priv = CAMEL_TEXT_INDEX_KEY_CURSOR (object)->priv;
-
-       if (priv->table != NULL) {
-               g_object_unref (priv->table);
-               priv->table = NULL;
-       }
+       g_clear_object (&priv->table);
 
        /* Chain up parent's dispose() method. */
        G_OBJECT_CLASS (camel_text_index_key_cursor_parent_class)->dispose (object);
diff --git a/src/camel/camel-vee-data-cache.c b/src/camel/camel-vee-data-cache.c
index ae488f625..9b83267d7 100644
--- a/src/camel/camel-vee-data-cache.c
+++ b/src/camel/camel-vee-data-cache.c
@@ -388,21 +388,9 @@ vee_data_cache_dispose (GObject *object)
        CamelVeeDataCachePrivate *priv;
 
        priv = CAMEL_VEE_DATA_CACHE (object)->priv;
-
-       if (priv->subfolder_hash != NULL) {
-               g_hash_table_destroy (priv->subfolder_hash);
-               priv->subfolder_hash = NULL;
-       }
-
-       if (priv->orig_message_uid_hash != NULL) {
-               g_hash_table_destroy (priv->orig_message_uid_hash);
-               priv->orig_message_uid_hash = NULL;
-       }
-
-       if (priv->vee_message_uid_hash != NULL) {
-               g_hash_table_destroy (priv->vee_message_uid_hash);
-               priv->vee_message_uid_hash = NULL;
-       }
+       g_clear_pointer (&priv->subfolder_hash, g_hash_table_destroy);
+       g_clear_pointer (&priv->orig_message_uid_hash, g_hash_table_destroy);
+       g_clear_pointer (&priv->vee_message_uid_hash, g_hash_table_destroy);
 
        /* Chain up to parent's dispose () method. */
        G_OBJECT_CLASS (camel_vee_data_cache_parent_class)->dispose (object);
diff --git a/src/camel/camel-vee-folder.c b/src/camel/camel-vee-folder.c
index 2b528b621..24feca551 100644
--- a/src/camel/camel-vee-folder.c
+++ b/src/camel/camel-vee-folder.c
@@ -676,9 +676,7 @@ vee_folder_finalize (GObject *object)
 
        g_async_queue_unref (vf->priv->change_queue);
 
-       if (vf->priv->vee_data_cache)
-               g_object_unref (vf->priv->vee_data_cache);
-       vf->priv->vee_data_cache = NULL;
+       g_clear_object (&vf->priv->vee_data_cache);
 
        /* Chain up to parent's finalize () method. */
        G_OBJECT_CLASS (camel_vee_folder_parent_class)->finalize (object);
diff --git a/src/camel/providers/imapx/camel-imapx-folder.c b/src/camel/providers/imapx/camel-imapx-folder.c
index 926f15904..793e4d175 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.c
+++ b/src/camel/providers/imapx/camel-imapx-folder.c
@@ -209,15 +209,8 @@ imapx_folder_dispose (GObject *object)
        CamelIMAPXFolder *folder = CAMEL_IMAPX_FOLDER (object);
        CamelStore *store;
 
-       if (folder->cache != NULL) {
-               g_object_unref (folder->cache);
-               folder->cache = NULL;
-       }
-
-       if (folder->search != NULL) {
-               g_object_unref (folder->search);
-               folder->search = NULL;
-       }
+       g_clear_object (&folder->cache);
+       g_clear_object (&folder->search);
 
        store = camel_folder_get_parent_store (CAMEL_FOLDER (folder));
        if (store != NULL) {
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index b04012da6..f82803641 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -755,10 +755,7 @@ imapx_untagged_capability (CamelIMAPXServer *is,
 
        g_mutex_lock (&is->priv->stream_lock);
 
-       if (is->priv->cinfo != NULL) {
-               imapx_free_capability (is->priv->cinfo);
-               is->priv->cinfo = NULL;
-       }
+       g_clear_pointer (&is->priv->cinfo, imapx_free_capability);
 
        g_mutex_unlock (&is->priv->stream_lock);
 
@@ -3074,9 +3071,7 @@ connected:
 
                        /* See if we got new capabilities
                         * in the STARTTLS response. */
-                       if (is->priv->cinfo)
-                               imapx_free_capability (is->priv->cinfo);
-                       is->priv->cinfo = NULL;
+                       g_clear_pointer (&is->priv->cinfo, imapx_free_capability);
                        if (ic->status->condition == IMAPX_CAPABILITY) {
                                is->priv->cinfo = ic->status->u.cinfo;
                                ic->status->u.cinfo = NULL;
@@ -3146,10 +3141,7 @@ exit:
                g_clear_object (&is->priv->connection);
                g_clear_object (&is->priv->subprocess);
 
-               if (is->priv->cinfo != NULL) {
-                       imapx_free_capability (is->priv->cinfo);
-                       is->priv->cinfo = NULL;
-               }
+               g_clear_pointer (&is->priv->cinfo, imapx_free_capability);
 
                g_mutex_unlock (&is->priv->stream_lock);
        }
@@ -3362,10 +3354,7 @@ camel_imapx_server_authenticate_sync (CamelIMAPXServer *is,
        if (result == CAMEL_AUTHENTICATION_ACCEPTED) {
                g_mutex_lock (&is->priv->stream_lock);
 
-               if (is->priv->cinfo) {
-                       imapx_free_capability (is->priv->cinfo);
-                       is->priv->cinfo = NULL;
-               }
+               g_clear_pointer (&is->priv->cinfo, imapx_free_capability);
 
                if (ic->status->condition == IMAPX_CAPABILITY) {
                        is->priv->cinfo = ic->status->u.cinfo;
@@ -4073,10 +4062,7 @@ camel_imapx_server_process_command_sync (CamelIMAPXServer *is,
        g_return_val_if_fail (CAMEL_IS_IMAPX_COMMAND (ic), FALSE);
 
        camel_imapx_command_close (ic);
-       if (ic->status) {
-               imapx_free_status (ic->status);
-               ic->status = NULL;
-       }
+       g_clear_pointer (&ic->status, imapx_free_status);
        ic->completed = FALSE;
 
        head = g_queue_peek_head_link (&ic->parts);
@@ -4257,10 +4243,7 @@ imapx_disconnect (CamelIMAPXServer *is)
        g_clear_object (&is->priv->connection);
        g_clear_object (&is->priv->subprocess);
 
-       if (is->priv->cinfo) {
-               imapx_free_capability (is->priv->cinfo);
-               is->priv->cinfo = NULL;
-       }
+       g_clear_pointer (&is->priv->cinfo, imapx_free_capability);
 
        g_mutex_unlock (&is->priv->stream_lock);
 
@@ -6321,10 +6304,7 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
                camel_folder_summary_remove_uids (camel_folder_get_folder_summary (folder), 
expunged_removed_list);
        }
 
-       if (expunged_changes) {
-               camel_folder_change_info_free (expunged_changes);
-               expunged_changes = NULL;
-       }
+       g_clear_pointer (&expunged_changes, camel_folder_change_info_free);
 
        if (expunged_removed_list) {
                g_list_free_full (expunged_removed_list, (GDestroyNotify) camel_pstring_free);
diff --git a/src/camel/providers/imapx/camel-imapx-utils.c b/src/camel/providers/imapx/camel-imapx-utils.c
index 3c2a3ed88..141f083e2 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.c
+++ b/src/camel/providers/imapx/camel-imapx-utils.c
@@ -939,9 +939,7 @@ imapx_parse_ext_optional (CamelIMAPXInputStream *stream,
  done:
        if (local_error != NULL) {
                g_propagate_error (error, local_error);
-               if (dinfo)
-                       camel_content_disposition_unref (dinfo);
-               dinfo = NULL;
+               g_clear_pointer (&dinfo, camel_content_disposition_unref);
        }
 
        return dinfo;
diff --git a/src/camel/providers/local/camel-local-summary.c b/src/camel/providers/local/camel-local-summary.c
index 256664397..09a897f38 100644
--- a/src/camel/providers/local/camel-local-summary.c
+++ b/src/camel/providers/local/camel-local-summary.c
@@ -83,11 +83,7 @@ local_summary_dispose (GObject *object)
        CamelLocalSummary *local_summary;
 
        local_summary = CAMEL_LOCAL_SUMMARY (object);
-
-       if (local_summary->index != NULL) {
-               g_object_unref (local_summary->index);
-               local_summary->index = NULL;
-       }
+       g_clear_object (&local_summary->index);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_local_summary_parent_class)->dispose (object);
diff --git a/src/camel/providers/local/camel-mbox-summary.c b/src/camel/providers/local/camel-mbox-summary.c
index a33f8a081..f637e179e 100644
--- a/src/camel/providers/local/camel-mbox-summary.c
+++ b/src/camel/providers/local/camel-mbox-summary.c
@@ -887,8 +887,7 @@ mbox_summary_sync_quick (CamelMboxSummary *mbs,
        g_object_unref (mp);
        if (fd != -1)
                close (fd);
-       if (info)
-               g_clear_object (&info);
+       g_clear_object (&info);
 
        camel_operation_pop_message (cancellable);
        camel_folder_summary_unlock (s);
diff --git a/src/camel/providers/nntp/camel-nntp-folder.c b/src/camel/providers/nntp/camel-nntp-folder.c
index b912a54cc..3295bf4b2 100644
--- a/src/camel/providers/nntp/camel-nntp-folder.c
+++ b/src/camel/providers/nntp/camel-nntp-folder.c
@@ -133,10 +133,7 @@ nntp_folder_finalize (GObject *object)
 {
        CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (object);
 
-       if (nntp_folder->changes) {
-               camel_folder_change_info_free (nntp_folder->changes);
-               nntp_folder->changes = NULL;
-       }
+       g_clear_pointer (&nntp_folder->changes, camel_folder_change_info_free);
 
        g_mutex_clear (&nntp_folder->priv->search_lock);
        g_mutex_clear (&nntp_folder->priv->cache_lock);
diff --git a/src/camel/providers/nntp/camel-nntp-stream.c b/src/camel/providers/nntp/camel-nntp-stream.c
index e6ed3cc89..0e7e77372 100644
--- a/src/camel/providers/nntp/camel-nntp-stream.c
+++ b/src/camel/providers/nntp/camel-nntp-stream.c
@@ -41,10 +41,7 @@ nntp_stream_dispose (GObject *object)
 {
        CamelNNTPStream *stream = CAMEL_NNTP_STREAM (object);
 
-       if (stream->source != NULL) {
-               g_object_unref (stream->source);
-               stream->source = NULL;
-       }
+       g_clear_object (&stream->source);
 
        /* Chain up to parent's dispose () method. */
        G_OBJECT_CLASS (camel_nntp_stream_parent_class)->dispose (object);
diff --git a/src/camel/providers/nntp/camel-nntp-summary.c b/src/camel/providers/nntp/camel-nntp-summary.c
index 5712800e5..fabee3d4f 100644
--- a/src/camel/providers/nntp/camel-nntp-summary.c
+++ b/src/camel/providers/nntp/camel-nntp-summary.c
@@ -276,10 +276,7 @@ add_range_xover (CamelNNTPSummary *cns,
                        }
                }
 
-               if (cns->priv->uid) {
-                       g_free (cns->priv->uid);
-                       cns->priv->uid = NULL;
-               }
+               g_clear_pointer (&cns->priv->uid, g_free);
 
                camel_name_value_array_clear (headers);
        }
@@ -381,10 +378,7 @@ add_range_head (CamelNNTPSummary *cns,
                                        camel_folder_change_info_recent_uid (changes, 
camel_message_info_get_uid (mi));
                                g_clear_object (&mi);
                        }
-                       if (cns->priv->uid) {
-                               g_free (cns->priv->uid);
-                               cns->priv->uid = NULL;
-                       }
+                       g_clear_pointer (&cns->priv->uid, g_free);
                }
        }
 
@@ -406,10 +400,7 @@ error:
        }
 
 ioerror:
-       if (cns->priv->uid) {
-               g_free (cns->priv->uid);
-               cns->priv->uid = NULL;
-       }
+       g_clear_pointer (&cns->priv->uid, g_free);
        g_object_unref (mp);
 
        g_clear_object (&nntp_stream);
diff --git a/src/camel/providers/pop3/camel-pop3-engine.c b/src/camel/providers/pop3/camel-pop3-engine.c
index 798d94180..0652ba948 100644
--- a/src/camel/providers/pop3/camel-pop3-engine.c
+++ b/src/camel/providers/pop3/camel-pop3-engine.c
@@ -45,10 +45,7 @@ pop3_engine_dispose (GObject *object)
 {
        CamelPOP3Engine *engine = CAMEL_POP3_ENGINE (object);
 
-       if (engine->stream != NULL) {
-               g_object_unref (engine->stream);
-               engine->stream = NULL;
-       }
+       g_clear_object (&engine->stream);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_pop3_engine_parent_class)->dispose (object);
diff --git a/src/camel/providers/pop3/camel-pop3-folder.c b/src/camel/providers/pop3/camel-pop3-folder.c
index 0931a0d37..49f69c2bb 100644
--- a/src/camel/providers/pop3/camel-pop3-folder.c
+++ b/src/camel/providers/pop3/camel-pop3-folder.c
@@ -260,10 +260,7 @@ pop3_folder_dispose (GObject *object)
                pop3_folder->uids = NULL;
        }
 
-       if (pop3_folder->uids_fi) {
-               g_hash_table_destroy (pop3_folder->uids_fi);
-               pop3_folder->uids_fi = NULL;
-       }
+       g_clear_pointer (&pop3_folder->uids_fi, g_hash_table_destroy);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_pop3_folder_parent_class)->dispose (object);
@@ -671,10 +668,7 @@ pop3_folder_refresh_info_sync (CamelFolder *folder,
                g_ptr_array_free (pop3_folder->uids, TRUE);
        }
 
-       if (pop3_folder->uids_fi) {
-               g_hash_table_destroy (pop3_folder->uids_fi);
-               pop3_folder->uids_fi = NULL;
-       }
+       g_clear_pointer (&pop3_folder->uids_fi, g_hash_table_destroy);
 
        /* Get a new working set. */
        pop3_folder->uids = g_ptr_array_new ();
diff --git a/src/camel/providers/pop3/camel-pop3-stream.c b/src/camel/providers/pop3/camel-pop3-stream.c
index c246174d3..365440cd7 100644
--- a/src/camel/providers/pop3/camel-pop3-stream.c
+++ b/src/camel/providers/pop3/camel-pop3-stream.c
@@ -39,10 +39,7 @@ pop3_stream_dispose (GObject *object)
 {
        CamelPOP3Stream *stream = CAMEL_POP3_STREAM (object);
 
-       if (stream->source != NULL) {
-               g_object_unref (stream->source);
-               stream->source = NULL;
-       }
+       g_clear_object (&stream->source);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (camel_pop3_stream_parent_class)->dispose (object);
diff --git a/src/examples/cursor/cursor-example.c b/src/examples/cursor/cursor-example.c
index b5d64d280..a8f7cc69d 100644
--- a/src/examples/cursor/cursor-example.c
+++ b/src/examples/cursor/cursor-example.c
@@ -177,15 +177,8 @@ cursor_example_dispose (GObject *object)
 
        cursor_example_cancel_timeout (example);
 
-       if (priv->client) {
-               g_object_unref (priv->client);
-               priv->client = NULL;
-       }
-
-       if (priv->cursor) {
-               g_object_unref (priv->cursor);
-               priv->cursor = NULL;
-       }
+       g_clear_object (&priv->client);
+       g_clear_object (&priv->cursor);
 
        G_OBJECT_CLASS (cursor_example_parent_class)->dispose (object);
 }
diff --git a/src/libebackend/e-backend.c b/src/libebackend/e-backend.c
index b48fe1fa8..fa30bc250 100644
--- a/src/libebackend/e-backend.c
+++ b/src/libebackend/e-backend.c
@@ -639,10 +639,7 @@ backend_dispose (GObject *object)
                priv->network_changed_handler_id = 0;
        }
 
-       if (priv->main_context != NULL) {
-               g_main_context_unref (priv->main_context);
-               priv->main_context = NULL;
-       }
+       g_clear_pointer (&priv->main_context, g_main_context_unref);
 
        if (priv->update_online_state != NULL) {
                g_source_destroy (priv->update_online_state);
diff --git a/src/libebackend/e-cache.c b/src/libebackend/e-cache.c
index 64ef47917..240040cf5 100644
--- a/src/libebackend/e-cache.c
+++ b/src/libebackend/e-cache.c
@@ -575,10 +575,7 @@ e_cache_sqlite_exec_internal (ECache *cache,
                        break;
                retries++;
 
-               if (errmsg) {
-                       sqlite3_free (errmsg);
-                       errmsg = NULL;
-               }
+               g_clear_pointer (&errmsg, sqlite3_free);
                g_thread_yield ();
                g_usleep (100 * 1000); /* Sleep for 100 ms */
 
@@ -3089,10 +3086,7 @@ e_cache_finalize (GObject *object)
        g_free (cache->priv->filename);
        cache->priv->filename = NULL;
 
-       if (cache->priv->db) {
-               sqlite3_close (cache->priv->db);
-               cache->priv->db = NULL;
-       }
+       g_clear_pointer (&cache->priv->db, sqlite3_close);
 
        g_rec_mutex_clear (&cache->priv->lock);
 
diff --git a/src/libebackend/e-collection-backend.c b/src/libebackend/e-collection-backend.c
index 7be6b8f18..4805a6933 100644
--- a/src/libebackend/e-collection-backend.c
+++ b/src/libebackend/e-collection-backend.c
@@ -609,10 +609,7 @@ collection_backend_forget_new_sources (ECollectionBackend *backend)
 
        g_mutex_lock (&backend->priv->unclaimed_resources_lock);
 
-       if (backend->priv->new_sources) {
-               g_hash_table_destroy (backend->priv->new_sources);
-               backend->priv->new_sources = NULL;
-       }
+       g_clear_pointer (&backend->priv->new_sources, g_hash_table_destroy);
 
        g_mutex_unlock (&backend->priv->unclaimed_resources_lock);
 }
diff --git a/src/libebackend/e-server-side-source.c b/src/libebackend/e-server-side-source.c
index 4ce73a6a9..f8c01a57d 100644
--- a/src/libebackend/e-server-side-source.c
+++ b/src/libebackend/e-server-side-source.c
@@ -1052,10 +1052,7 @@ server_side_source_dispose (GObject *object)
 
        g_weak_ref_set (&priv->oauth2_support, NULL);
 
-       if (priv->file != NULL) {
-               g_object_unref (priv->file);
-               priv->file = NULL;
-       }
+       g_clear_object (&priv->file);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_server_side_source_parent_class)->dispose (object);
diff --git a/src/libebackend/e-source-registry-server.c b/src/libebackend/e-source-registry-server.c
index 69637aa15..c2c0145a5 100644
--- a/src/libebackend/e-source-registry-server.c
+++ b/src/libebackend/e-source-registry-server.c
@@ -784,10 +784,7 @@ source_registry_server_dispose (GObject *object)
        }
        g_mutex_unlock (&priv->file_monitor_lock);
 
-       if (priv->main_context != NULL) {
-               g_main_context_unref (priv->main_context);
-               priv->main_context = NULL;
-       }
+       g_clear_pointer (&priv->main_context, g_main_context_unref);
 
        g_clear_object (&priv->object_manager);
        g_clear_object (&priv->source_manager);
diff --git a/src/libebackend/e-user-prompter-server.c b/src/libebackend/e-user-prompter-server.c
index a0432f6c3..f9e7088b7 100644
--- a/src/libebackend/e-user-prompter-server.c
+++ b/src/libebackend/e-user-prompter-server.c
@@ -333,11 +333,7 @@ user_prompter_server_dispose (GObject *object)
        EUserPrompterServerPrivate *priv;
 
        priv = E_USER_PROMPTER_SERVER (object)->priv;
-
-       if (priv->dbus_prompter != NULL) {
-               g_object_unref (priv->dbus_prompter);
-               priv->dbus_prompter = NULL;
-       }
+       g_clear_object (&priv->dbus_prompter);
 
        g_slist_free_full (priv->prompts, prompt_request_free);
        g_hash_table_remove_all (priv->extensions);
diff --git a/src/libedataserver/e-categories.c b/src/libedataserver/e-categories.c
index 46bfcd0f7..04c96863b 100644
--- a/src/libedataserver/e-categories.c
+++ b/src/libedataserver/e-categories.c
@@ -497,15 +497,8 @@ finalize_categories (void)
                idle_id = 0;
        }
 
-       if (categories_table != NULL) {
-               g_hash_table_destroy (categories_table);
-               categories_table = NULL;
-       }
-
-       if (listeners != NULL) {
-               g_object_unref (listeners);
-               listeners = NULL;
-       }
+       g_clear_pointer (&categories_table, g_hash_table_destroy);
+       g_clear_object (&listeners);
 
        initialized = FALSE;
 
diff --git a/src/libedataserver/e-client.c b/src/libedataserver/e-client.c
index 55307d4d8..bc166cabd 100644
--- a/src/libedataserver/e-client.c
+++ b/src/libedataserver/e-client.c
@@ -336,12 +336,7 @@ client_dispose (GObject *object)
        EClientPrivate *priv;
 
        priv = E_CLIENT (object)->priv;
-
-       if (priv->main_context != NULL) {
-               g_main_context_unref (priv->main_context);
-               priv->main_context = NULL;
-       }
-
+       g_clear_pointer (&priv->main_context, g_main_context_unref);
        g_clear_object (&priv->source);
 
        g_free (priv->bus_name);
diff --git a/src/libedataserver/e-sexp.c b/src/libedataserver/e-sexp.c
index 910704390..dd456ec75 100644
--- a/src/libedataserver/e-sexp.c
+++ b/src/libedataserver/e-sexp.c
@@ -176,8 +176,7 @@ e_sexp_fatal_error (ESExp *sexp,
        g_warn_if_fail (E_IS_SEXP (sexp));
        g_warn_if_fail (why != NULL);
 
-       if (sexp->priv->error)
-               g_free (sexp->priv->error);
+       g_free (sexp->priv->error);
 
        va_start (args, why);
        sexp->priv->error = g_strdup_vprintf (why, args);
diff --git a/src/libedataserver/e-source-camel.c b/src/libedataserver/e-source-camel.c
index 05bd5f1f1..88a673516 100644
--- a/src/libedataserver/e-source-camel.c
+++ b/src/libedataserver/e-source-camel.c
@@ -428,11 +428,7 @@ source_camel_dispose (GObject *object)
        ESourceCamelPrivate *priv;
 
        priv = E_SOURCE_CAMEL (object)->priv;
-
-       if (priv->settings != NULL) {
-               g_object_unref (priv->settings);
-               priv->settings = NULL;
-       }
+       g_clear_object (&priv->settings);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_source_camel_parent_class)->dispose (object);
diff --git a/src/libedataserver/e-source-local.c b/src/libedataserver/e-source-local.c
index 90fa2accb..ac1cabecc 100644
--- a/src/libedataserver/e-source-local.c
+++ b/src/libedataserver/e-source-local.c
@@ -104,11 +104,7 @@ source_local_finalize (GObject *object)
        ESourceLocalPrivate *priv;
 
        priv = E_SOURCE_LOCAL (object)->priv;
-
-       if (priv->custom_file != NULL) {
-               g_object_unref (priv->custom_file);
-               priv->custom_file = NULL;
-       }
+       g_clear_object (&priv->custom_file);
 
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_source_local_parent_class)->finalize (object);
diff --git a/src/libedataserver/e-source-mail-signature.c b/src/libedataserver/e-source-mail-signature.c
index a1f4f41ee..f5818ec91 100644
--- a/src/libedataserver/e-source-mail-signature.c
+++ b/src/libedataserver/e-source-mail-signature.c
@@ -124,11 +124,7 @@ source_mail_signature_dispose (GObject *object)
        ESourceMailSignaturePrivate *priv;
 
        priv = E_SOURCE_MAIL_SIGNATURE (object)->priv;
-
-       if (priv->file != NULL) {
-               g_object_unref (priv->file);
-               priv->file = NULL;
-       }
+       g_clear_object (&priv->file);
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_source_mail_signature_parent_class)->
diff --git a/src/libedataserver/e-source-registry.c b/src/libedataserver/e-source-registry.c
index 51b23dbd1..8e73c8930 100644
--- a/src/libedataserver/e-source-registry.c
+++ b/src/libedataserver/e-source-registry.c
@@ -1297,16 +1297,8 @@ source_registry_dispose (GObject *object)
        ESourceRegistryPrivate *priv;
 
        priv = E_SOURCE_REGISTRY (object)->priv;
-
-       if (priv->dbus_object_manager != NULL) {
-               g_object_unref (priv->dbus_object_manager);
-               priv->dbus_object_manager = NULL;
-       }
-
-       if (priv->dbus_source_manager != NULL) {
-               g_object_unref (priv->dbus_source_manager);
-               priv->dbus_source_manager = NULL;
-       }
+       g_clear_object (&priv->dbus_object_manager);
+       g_clear_object (&priv->dbus_source_manager);
 
        /* Terminate the manager thread after GDBus objects,
           because they can schedule GSource-s in the main context there. */
@@ -1316,10 +1308,7 @@ source_registry_dispose (GObject *object)
                priv->manager_thread = NULL;
        }
 
-       if (priv->thread_closure) {
-               thread_closure_free (priv->thread_closure);
-               priv->thread_closure = NULL;
-       }
+       g_clear_pointer (&priv->thread_closure, thread_closure_free);
 
        g_hash_table_remove_all (priv->object_path_table);
 
diff --git a/src/libedataserver/e-source.c b/src/libedataserver/e-source.c
index a77fc27f9..353a3e748 100644
--- a/src/libedataserver/e-source.c
+++ b/src/libedataserver/e-source.c
@@ -861,10 +861,7 @@ source_update_connection_status (ESource *source)
        g_return_if_fail (E_IS_SOURCE (source));
 
        g_mutex_lock (&source->priv->connection_status_change_lock);
-       if (source->priv->connection_status_change != NULL) {
-               g_source_unref (source->priv->connection_status_change);
-               source->priv->connection_status_change = NULL;
-       }
+       g_clear_pointer (&source->priv->connection_status_change, g_source_unref);
        g_mutex_unlock (&source->priv->connection_status_change_lock);
 
        g_object_freeze_notify (G_OBJECT (source));
@@ -1034,10 +1031,7 @@ source_idle_changed_cb (gpointer user_data)
                return FALSE;
 
        g_mutex_lock (&source->priv->changed_lock);
-       if (source->priv->changed != NULL) {
-               g_source_unref (source->priv->changed);
-               source->priv->changed = NULL;
-       }
+       g_clear_pointer (&source->priv->changed, g_source_unref);
        g_mutex_unlock (&source->priv->changed_lock);
 
        g_signal_emit (source, signals[CHANGED], 0);
@@ -1246,10 +1240,7 @@ source_dispose (GObject *object)
 
        g_mutex_unlock (&priv->property_lock);
 
-       if (priv->main_context != NULL) {
-               g_main_context_unref (priv->main_context);
-               priv->main_context = NULL;
-       }
+       g_clear_pointer (&priv->main_context, g_main_context_unref);
 
        /* XXX Maybe not necessary to acquire the lock? */
        g_mutex_lock (&priv->changed_lock);
diff --git a/src/libedataserver/e-xml-document.c b/src/libedataserver/e-xml-document.c
index e5e51f63a..281cbc9a6 100644
--- a/src/libedataserver/e-xml-document.c
+++ b/src/libedataserver/e-xml-document.c
@@ -44,18 +44,12 @@ e_xml_document_finalize (GObject *object)
 {
        EXmlDocument *xml = E_XML_DOCUMENT (object);
 
-       if (xml->priv->doc) {
-               xmlFreeDoc (xml->priv->doc);
-               xml->priv->doc = NULL;
-       }
+       g_clear_pointer (&xml->priv->doc, xmlFreeDoc);
 
        xml->priv->root = NULL;
        xml->priv->current_element = NULL;
 
-       if (xml->priv->namespaces_by_href) {
-               g_hash_table_destroy (xml->priv->namespaces_by_href);
-               xml->priv->namespaces_by_href = NULL;
-       }
+       g_clear_pointer (&xml->priv->namespaces_by_href, g_hash_table_destroy);
 
        /* Chain up to parent's method. */
        G_OBJECT_CLASS (e_xml_document_parent_class)->finalize (object);
diff --git a/src/services/evolution-source-registry/evolution-source-registry-migrate-sources.c 
b/src/services/evolution-source-registry/evolution-source-registry-migrate-sources.c
index 90a5bec72..87c69c9c3 100644
--- a/src/services/evolution-source-registry/evolution-source-registry-migrate-sources.c
+++ b/src/services/evolution-source-registry/evolution-source-registry-migrate-sources.c
@@ -1704,25 +1704,10 @@ migrate_parse_account_xml_end_element (GMarkupParseContext *context,
                                parse_data->collection_key_file = NULL;
                        }
 
-                       if (parse_data->file != NULL) {
-                               g_object_unref (parse_data->file);
-                               parse_data->file = NULL;
-                       }
-
-                       if (parse_data->identity_file != NULL) {
-                               g_object_unref (parse_data->identity_file);
-                               parse_data->identity_file = NULL;
-                       }
-
-                       if (parse_data->transport_file != NULL) {
-                               g_object_unref (parse_data->transport_file);
-                               parse_data->transport_file = NULL;
-                       }
-
-                       if (parse_data->collection_file != NULL) {
-                               g_object_unref (parse_data->collection_file);
-                               parse_data->collection_file = NULL;
-                       }
+                       g_clear_object (&parse_data->file);
+                       g_clear_object (&parse_data->identity_file);
+                       g_clear_object (&parse_data->transport_file);
+                       g_clear_object (&parse_data->collection_file);
 
                        parse_data->skip = FALSE;
                }
@@ -2150,10 +2135,7 @@ migrate_parse_signature_xml_end_element (GMarkupParseContext *context,
                                parse_data->key_file = NULL;
                        }
 
-                       if (parse_data->file != NULL) {
-                               g_object_unref (parse_data->file);
-                               parse_data->file = NULL;
-                       }
+                       g_clear_object (&parse_data->file);
 
                        parse_data->skip = FALSE;
 
@@ -3147,18 +3129,12 @@ migrate_parse_source_xml_end_element (GMarkupParseContext *context,
                                parse_data->key_file = NULL;
                        }
 
-                       if (parse_data->file != NULL) {
-                               g_object_unref (parse_data->file);
-                               parse_data->file = NULL;
-                       }
+                       g_clear_object (&parse_data->file);
 
                        g_free (parse_data->mangled_uri);
                        parse_data->mangled_uri = NULL;
 
-                       if (parse_data->soup_uri != NULL) {
-                               soup_uri_free (parse_data->soup_uri);
-                               parse_data->soup_uri = NULL;
-                       }
+                       g_clear_pointer (&parse_data->soup_uri, soup_uri_free);
 
                        parse_data->property_func = NULL;
 


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