[balsa/wip/gtk4] More g_clear_* stuff



commit a5f4129de33f4aadeb2be64fcf7dd9d8d624374d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Jul 12 16:40:25 2018 -0400

    More g_clear_* stuff

 libbalsa/address-book-gpe.c      | 10 +++-------
 libbalsa/address-book-ldap.c     | 16 ++++++++--------
 libbalsa/address-book-text.c     |  6 ++----
 libbalsa/body.c                  |  5 +----
 libbalsa/filter-file.c           | 12 ++++--------
 libbalsa/gforest.c               | 34 ----------------------------------
 libbalsa/gmime-multipart-crypt.c |  6 ++----
 libbalsa/html.c                  |  9 +++------
 libbalsa/libbalsa-conf.c         |  6 ++----
 libbalsa/libbalsa-gpgme-keys.c   |  3 +--
 libbalsa/libbalsa-gpgme.c        |  6 ++----
 libbalsa/libbalsa.c              |  9 +++------
 libbalsa/mailbox.c               |  3 +--
 libbalsa/mailbox_imap.c          | 15 +++------------
 libbalsa/mailbox_local.c         |  3 +--
 libbalsa/mailbox_maildir.c       | 10 ++++------
 libbalsa/mailbox_mbox.c          |  9 ++-------
 libbalsa/mailbox_pop3.c          | 12 ++++--------
 libbalsa/message.c               | 10 +++-------
 libbalsa/send.c                  |  6 ++----
 libbalsa/server.c                | 12 ++++--------
 libnetclient/net-client-pop.c    |  3 +--
 libnetclient/net-client-siobuf.c |  3 +--
 libnetclient/net-client-smtp.c   |  6 ++----
 libnetclient/net-client-utils.c  |  3 +--
 libnetclient/net-client.c        |  3 +--
 src/ab-main.c                    | 14 ++++++--------
 src/balsa-icons.c                |  5 +----
 src/balsa-index.c                | 10 ++++------
 src/balsa-message.c              | 15 +++++----------
 src/balsa-mime-widget-crypto.c   |  3 +--
 src/balsa-print-object-header.c  |  3 +--
 src/compose-window.c             |  7 +++----
 src/filter-edit-callbacks.c      |  4 +---
 src/folder-conf.c                |  3 +--
 src/main-window.c                |  6 ++----
 src/main.c                       | 21 +++++++--------------
 src/pref-manager.c               |  3 +--
 src/spell-check.c                |  3 +--
 39 files changed, 95 insertions(+), 222 deletions(-)
---
diff --git a/libbalsa/address-book-gpe.c b/libbalsa/address-book-gpe.c
index 48282e8ca..9617529ca 100644
--- a/libbalsa/address-book-gpe.c
+++ b/libbalsa/address-book-gpe.c
@@ -148,14 +148,11 @@ libbalsa_address_book_gpe_new(const gchar *name)
 static void
 libbalsa_address_book_gpe_close_db(LibBalsaAddressBookGpe * ab_gpe)
 {
-    if (ab_gpe->db) {
 #ifdef HAVE_SQLITE3
-       sqlite3_close(ab_gpe->db);
+    g_clear_pointer(&ab_gpe->db, sqlite3_close);
 #else                           /* HAVE_SQLITE3 */
-       sqlite_close(ab_gpe->db);
+    g_clear_pointer(&ab_gpe->db, sqlite_close);
 #endif                          /* HAVE_SQLITE3 */
-       ab_gpe->db = NULL;
-    }
 }
 
 /*
@@ -185,8 +182,7 @@ libbalsa_address_book_gpe_open_db(LibBalsaAddressBookGpe * ab_gpe)
     if (sqlite3_open(name, &ab_gpe->db) != SQLITE_OK) {
         printf("Cannot open “%s”: %s\n", name, sqlite3_errmsg(ab_gpe->db));
         g_free(name);
-        sqlite3_close(ab_gpe->db);
-        ab_gpe->db = NULL;
+        g_clear_pointer(&ab_gpe->db, sqlite3_close);
         return 0;
     }
     g_free(name);
diff --git a/libbalsa/address-book-ldap.c b/libbalsa/address-book-ldap.c
index 6278639c9..62858c49d 100644
--- a/libbalsa/address-book-ldap.c
+++ b/libbalsa/address-book-ldap.c
@@ -879,21 +879,21 @@ libbalsa_address_book_ldap_load_config(LibBalsaAddressBook * ab,
 
     ldap->host = libbalsa_conf_get_string("Host");
     ldap->base_dn = libbalsa_conf_get_string("BaseDN");
-    if(ldap->base_dn && *ldap->base_dn == 0) { 
-       g_free(ldap->base_dn); ldap->base_dn = NULL; 
+    if(ldap->base_dn && *ldap->base_dn == 0) {
+        g_clear_pointer(&ldap->base_dn, g_free);
     }
 
     ldap->bind_dn = libbalsa_conf_private_get_string("BindDN");
-    if(ldap->bind_dn && *ldap->bind_dn == 0) { 
-       g_free(ldap->bind_dn); ldap->bind_dn = NULL; 
+    if(ldap->bind_dn && *ldap->bind_dn == 0) {
+        g_clear_pointer(&ldap->bind_dn, g_free);
     }
     ldap->passwd = libbalsa_conf_private_get_string("Passwd");
-    if(ldap->passwd && *ldap->passwd == 0) { 
-       g_free(ldap->passwd); ldap->passwd = NULL; 
+    if(ldap->passwd && *ldap->passwd == 0) {
+        g_clear_pointer(&ldap->passwd, g_free);
     }
     ldap->priv_book_dn = libbalsa_conf_get_string("BookDN");
-    if(ldap->priv_book_dn && *ldap->priv_book_dn == 0) { 
-       g_free(ldap->priv_book_dn); ldap->priv_book_dn = NULL; 
+    if(ldap->priv_book_dn && *ldap->priv_book_dn == 0) {
+        g_clear_pointer(&ldap->priv_book_dn, g_free);
     }
     ldap->enable_tls = libbalsa_conf_get_bool("EnableTLS");
 
diff --git a/libbalsa/address-book-text.c b/libbalsa/address-book-text.c
index 88aa3ee69..e744158c3 100644
--- a/libbalsa/address-book-text.c
+++ b/libbalsa/address-book-text.c
@@ -293,10 +293,8 @@ lbab_text_load_file(LibBalsaAddressBookText * ab_text, FILE * stream)
 
         item = lbab_text_item_new();
         item->begin = ftell(stream);
-        if (parse_address(stream, item->address, NULL, NULL) != LBABERR_OK) {
-            g_object_unref(item->address);
-            item->address = NULL;
-        }
+        if (parse_address(stream, item->address, NULL, NULL) != LBABERR_OK)
+            g_clear_object(&item->address);
         item->end = ftell(stream);
         list = g_slist_prepend(list, item);
     }
diff --git a/libbalsa/body.c b/libbalsa/body.c
index 37fac484c..613d4b1a9 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -259,10 +259,7 @@ libbalsa_message_body_set_parts(LibBalsaMessageBody * body)
     /* Free any parts that weren't used; the test isn't strictly
      * necessary, but it should fail unless something really strange has
      * happened, so it's worth including. */
-    if (*next_part) {
-       libbalsa_message_body_free(*next_part);
-       *next_part = NULL;
-    }
+    g_clear_pointer(next_part, libbalsa_message_body_free);
 }
 
 void
diff --git a/libbalsa/filter-file.c b/libbalsa/filter-file.c
index d50dbc24c..bc98341b1 100644
--- a/libbalsa/filter-file.c
+++ b/libbalsa/filter-file.c
@@ -61,14 +61,10 @@ libbalsa_filter_new_from_config(void)
     newf->action_string = libbalsa_conf_get_string("Action-string");
     newf->condition     = libbalsa_condition_new_from_string(&p);
     g_free(str);
-    if (newf->sound[0]=='\0') {
-       g_free(newf->sound);
-       newf->sound=NULL;
-    }
-    if (newf->popup_text[0]=='\0') {
-       g_free(newf->popup_text);
-       newf->popup_text=NULL;
-    }
+    if (newf->sound[0] == '\0')
+       g_clear_pointer(&newf->sound, g_free);
+    if (newf->popup_text[0] == '\0')
+       g_clear_pointer(&newf->popup_text, g_free);
 
     return newf;
 }
diff --git a/libbalsa/gmime-multipart-crypt.c b/libbalsa/gmime-multipart-crypt.c
index 465f56186..ca909452b 100644
--- a/libbalsa/gmime-multipart-crypt.c
+++ b/libbalsa/gmime-multipart-crypt.c
@@ -443,10 +443,8 @@ g_mime_gpgme_mpe_decrypt(GMimeMultipartEncrypted * mpe,
 
     g_return_val_if_fail(GMIME_IS_MULTIPART_ENCRYPTED(mpe), NULL);
 
-    if (signature && *signature) {
-       g_object_unref(G_OBJECT(*signature));
-       *signature = NULL;
-    }
+    if (signature)
+        g_clear_object(signature);
 
     protocol =
        g_mime_object_get_content_type_parameter(GMIME_OBJECT(mpe),
diff --git a/libbalsa/html.c b/libbalsa/html.c
index 4b833f492..039c66908 100644
--- a/libbalsa/html.c
+++ b/libbalsa/html.c
@@ -235,8 +235,7 @@ lbh_mouse_target_changed_cb(WebKitWebView       * web_view,
         return;
 
     if (info->uri != NULL) {
-        g_free(info->uri);
-        info->uri = NULL;
+        g_clear_pointer(&info->uri);
         (*info->hover_cb) (NULL);
     }
 
@@ -376,8 +375,7 @@ lbh_info_bar_response_cb(GtkInfoBar * info_bar,
         }
     }
 
-    gtk_widget_destroy(info->info_bar);
-    info->info_bar = NULL;
+    g_clear_pointer(&info->info_bar, gtk_widget_destroy);
 }
 
 static void
@@ -460,8 +458,7 @@ lbh_resource_notify_response_cb(WebKitWebResource * resource,
                 webkit_web_resource_get_uri(resource));
         /* web_view is loading an image from its cache, so we do not
          * need to ask the user for permission to download */
-        gtk_widget_destroy(info->info_bar);
-        info->info_bar = NULL;
+        g_clear_pointer(&info->info_bar, gtk_widget_destroy);
     } else {
         g_debug("%s %s null info_bar", __func__,
                 webkit_web_resource_get_uri(resource));
diff --git a/libbalsa/libbalsa-conf.c b/libbalsa/libbalsa-conf.c
index 3db4010fa..3921a55c3 100644
--- a/libbalsa/libbalsa-conf.c
+++ b/libbalsa/libbalsa-conf.c
@@ -465,10 +465,8 @@ libbalsa_conf_get_vector_with_default(const char *path, gint * argcp,
 static void
 lbc_drop_all(LibBalsaConf * conf)
 {
-    g_key_file_free(conf->key_file);
-    conf->key_file = NULL;
-    g_free(conf->path);
-    conf->path = NULL;
+    g_clear_pointer(&conf->key_file, g_key_file_free);
+    g_clear_pointer(&conf->path, g_free);
     conf->changes = 0;
 }
 
diff --git a/libbalsa/libbalsa-gpgme-keys.c b/libbalsa/libbalsa-gpgme-keys.c
index f45566e73..0e8fb6880 100644
--- a/libbalsa/libbalsa-gpgme-keys.c
+++ b/libbalsa/libbalsa-gpgme-keys.c
@@ -172,8 +172,7 @@ libbalsa_gpgme_load_key(gpgme_ctx_t   ctx,
                                if (gpgme_err == GPG_ERR_NO_ERROR) {
                                        libbalsa_gpgme_set_error(error, GPG_ERR_AMBIGUOUS, _("ambiguous keys 
for “%s”"), fingerprint);
                                        gpgme_key_unref(next_key);
-                                       gpgme_key_unref(key);
-                                       key = NULL;
+                                        g_clear_pointer(&key, gpgme_key_unref);
                                }
                        }
                }
diff --git a/libbalsa/libbalsa-gpgme.c b/libbalsa/libbalsa-gpgme.c
index a09f80704..402310aad 100644
--- a/libbalsa/libbalsa-gpgme.c
+++ b/libbalsa/libbalsa-gpgme.c
@@ -1084,10 +1084,8 @@ gpgme_build_recipients(gpgme_ctx_t   ctx,
                rcpt[num_rcpts] = key;
        }
 
-       if (select_res != GPG_ERR_NO_ERROR) {
-               release_keylist(rcpt);
-               rcpt = NULL;
-       }
+       if (select_res != GPG_ERR_NO_ERROR)
+                g_clear_pointer(&rcpt, release_keylist);
 
        return rcpt;
 }
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index b8449d13e..6300ad112 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -517,10 +517,8 @@ get_gnutls_cert(GTlsCertificate *cert)
                data.data = cert_der->data;
                data.size = cert_der->len;
                gnutls_res = gnutls_x509_crt_import(res_crt, &data, GNUTLS_X509_FMT_DER);
-               if (gnutls_res != GNUTLS_E_SUCCESS) {
-                       gnutls_x509_crt_deinit(res_crt);
-                       res_crt = NULL;
-               }
+               if (gnutls_res != GNUTLS_E_SUCCESS)
+                        g_clear_pointer(&res_crt, gnutls_x509_crt_deinit);
                g_byte_array_unref(cert_der);
        }
     } else {
@@ -539,8 +537,7 @@ gnutls_get_dn(gnutls_x509_crt_t cert, int (*load_fn)(gnutls_x509_crt_t cert, cha
     (void) load_fn(cert, NULL, &buf_size);
     str_buf = g_malloc0(buf_size + 1U);
     if (load_fn(cert, str_buf, &buf_size) != GNUTLS_E_SUCCESS) {
-       g_free(str_buf);
-       str_buf = NULL;
+       g_clear_pointer(&str_buf, g_free);
     } else {
        libbalsa_utf8_sanitize(&str_buf, TRUE, NULL);
     }
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index d76d319ee..e28e15d54 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -452,8 +452,7 @@ libbalsa_mailbox_index_entry_clear(LibBalsaMailbox *mailbox,
     if (msgno <= priv->mindex->len) {
         LibBalsaMailboxIndexEntry **entry = (LibBalsaMailboxIndexEntry **)
             &g_ptr_array_index(priv->mindex, msgno - 1);
-        lbm_index_entry_free(*entry);
-        *entry = NULL;
+        g_clear_pointer(entry, lbm_index_entry_free);
 
         libbalsa_mailbox_msgno_changed(mailbox, msgno);
     }
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 0759e3148..eb2c9f450 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -1531,12 +1531,7 @@ libbalsa_mailbox_imap_message_match(LibBalsaMailbox           *mailbox,
 static void
 libbalsa_mailbox_imap_search_iter_free(LibBalsaMailboxSearchIter *iter)
 {
-    GHashTable *matchings = iter->user_data;
-
-    if (matchings) {
-        g_hash_table_destroy(matchings);
-        iter->user_data = NULL;
-    }
+    g_clear_pointer(&iter->user_data, g_hash_table_destroy);
     /* iter->condition and iter are freed in the LibBalsaMailbox method. */
 }
 
@@ -1766,8 +1761,7 @@ libbalsa_mailbox_imap_get_matchings(LibBalsaMailboxImap *mbox,
     g_hash_table_destroy(cbdata->uids);
     /* Clean up on error */
     if (rc != IMR_OK) {
-       g_hash_table_destroy(cbdata->res);
-       cbdata->res = NULL;
+        g_clear_pointer(&cbdata->res, g_hash_table_destroy);
        *err = TRUE;
        libbalsa_information(LIBBALSA_INFORMATION_DEBUG,
                             _("IMAP SEARCH command failed for mailbox %s\n"
@@ -3139,10 +3133,7 @@ struct MultiAppendCbData {
 static void
 macd_clear(struct MultiAppendCbData *macd)
 {
-    if (macd->outstream) {
-        g_object_unref(macd->outstream);
-        macd->outstream = NULL;
-    }
+    g_clear_object(&macd->outstream);
 }
 
 
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 0d2f9a34d..d9c651f93 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -848,8 +848,7 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox *mailbox,
         for (i = priv->threading_info->len; i > 0;) {
             gpointer *entry =
                 &g_ptr_array_index(priv->threading_info, --i);
-            lbm_local_free_info(*entry);
-            *entry = NULL;
+            g_clear_pointer(entry, lbm_local_free_info);
         }
     }
 
diff --git a/libbalsa/mailbox_maildir.c b/libbalsa/mailbox_maildir.c
index a177411ef..abb64a7ab 100644
--- a/libbalsa/mailbox_maildir.c
+++ b/libbalsa/mailbox_maildir.c
@@ -272,12 +272,10 @@ static void
 libbalsa_mailbox_maildir_finalize(GObject *object)
 {
     LibBalsaMailboxMaildir *mdir = LIBBALSA_MAILBOX_MAILDIR(object);
-    g_free(mdir->curdir);
-    mdir->curdir = NULL;
-    g_free(mdir->newdir);
-    mdir->newdir = NULL;
-    g_free(mdir->tmpdir);
-    mdir->tmpdir = NULL;
+
+    g_clear_pointer(&mdir->curdir, g_free);
+    g_clear_pointer(&mdir->newdir, g_free);
+    g_clear_pointer(&mdir->tmpdir, g_free);
 
     G_OBJECT_CLASS(libbalsa_mailbox_maildir_parent_class)->finalize(object);
 }
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index 6a879f317..533780d2a 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -1210,13 +1210,8 @@ libbalsa_mailbox_mbox_close_mailbox(LibBalsaMailbox *mailbox,
     }
 
     /* Now it's safe to close the stream and free the message info. */
-    if (mbox->gmime_stream) {
-        g_object_unref(mbox->gmime_stream);
-        mbox->gmime_stream = NULL;
-    }
-
-    free_messages_info(mbox->msgno_2_msg_info);
-    mbox->msgno_2_msg_info = NULL;
+    g_clear_object(&mbox->gmime_stream);
+    g_clear_pointer(&mbox->msgno_2_msg_info, free_messages_info);
 }
 
 
diff --git a/libbalsa/mailbox_pop3.c b/libbalsa/mailbox_pop3.c
index 159b47d18..10d7e398e 100644
--- a/libbalsa/mailbox_pop3.c
+++ b/libbalsa/mailbox_pop3.c
@@ -286,8 +286,7 @@ pop_handler_new(const gchar *filter_path,
                         _("Passing POP message to %s failed: %s"),
                         filter_path,
                         g_strerror(errno));
-            g_free(res);
-            res = NULL;
+            g_clear_pointer(&res, g_free);
         } else {
             res->path = g_strdup(filter_path);
         }
@@ -573,8 +572,7 @@ libbalsa_mailbox_pop3_startup(LibBalsaServer      *server,
                              error->message);
         g_error_free(error);
         net_client_shutdown(NET_CLIENT(pop));
-        g_object_unref(G_OBJECT(pop));
-        pop = NULL;
+        g_clear_object(&pop);
     }
 
     return pop;
@@ -817,10 +815,8 @@ libbalsa_mailbox_pop3_load_config(LibBalsaMailbox *mailbox,
     mailbox_pop3->enable_pipe        = libbalsa_conf_get_bool("EnablePipe=false");
     mailbox_pop3->filter             = libbalsa_conf_get_bool("Filter=false");
     mailbox_pop3->filter_cmd         = libbalsa_conf_get_string("FilterCmd");
-    if ((mailbox_pop3->filter_cmd != NULL) && (mailbox_pop3->filter_cmd[0] == '\0')) {
-        g_free(mailbox_pop3->filter_cmd);
-        mailbox_pop3->filter_cmd = NULL;
-    }
+    if ((mailbox_pop3->filter_cmd != NULL) && (mailbox_pop3->filter_cmd[0] == '\0'))
+        g_clear_pointer(&mailbox_pop3->filter_cmd, g_free);
 
     if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->load_config) {
         LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_pop3_parent_class)->
diff --git a/libbalsa/message.c b/libbalsa/message.c
index 02305af96..11ce94e12 100644
--- a/libbalsa/message.c
+++ b/libbalsa/message.c
@@ -239,13 +239,10 @@ lb_message_headers_extra_destroy(LibBalsaMessageHeaders *headers)
 void
 libbalsa_message_headers_destroy(LibBalsaMessageHeaders *headers)
 {
-    if (!headers)
+    if (headers == NULL)
         return;
 
-
-    g_free(headers->subject);
-    headers->subject = NULL;
-
+    g_clear_pointer(&headers->subject, g_free);
     g_clear_object(&headers->from);
     g_clear_object(&headers->to_list);
     g_clear_object(&headers->content_type);
@@ -734,8 +731,7 @@ libbalsa_message_body_unref(LibBalsaMessage *message)
     if (message->mailbox)
         libbalsa_lock_mailbox(message->mailbox);
     if (--message->body_ref == 0) {
-        libbalsa_message_body_free(message->body_list);
-        message->body_list = NULL;
+        g_clear_pointer(&message->body_list, libbalsa_message_body_free);
         if (message->mailbox)
             libbalsa_mailbox_release_message(message->mailbox, message);
 
diff --git a/libbalsa/send.c b/libbalsa/send.c
index e8b97bf6c..7b8b59fec 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -799,8 +799,7 @@ lbs_process_queue_init_session(LibBalsaServer* server)
                        libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Cannot load certificate file %s: 
%s"), libbalsa_server_get_cert_file(server),
                                error->message);
                        g_error_free(error);
-                       g_object_unref(session);
-                       session = NULL;
+                        g_clear_object(&session);
                }
        } else {
                /* connect signals */
@@ -1098,8 +1097,7 @@ balsa_send_message_real(SendMessageInfo *info)
     g_idle_add((GSourceFunc) balsa_send_message_real_idle_cb, g_object_ref(info->outbox));
 
     /* finalise the SMTP session (which may be slow) */
-    g_object_unref(G_OBJECT(info->session));
-    info->session = NULL;
+    g_clear_object(&info->session);
 
     /* clean up */
     if (!info->no_dialog) {
diff --git a/libbalsa/server.c b/libbalsa/server.c
index 771082e7f..444c9c033 100644
--- a/libbalsa/server.c
+++ b/libbalsa/server.c
@@ -347,8 +347,7 @@ libbalsa_server_load_config(LibBalsaServer * server)
                                         "user",     priv->user,
                                         NULL);
         if (err) {
-            libbalsa_free_password(priv->passwd);
-            priv->passwd = NULL;
+            g_clear_pointer(&priv->passwd, libbalsa_free_password);
             printf(_("Error looking up password for %s@%s: %s\n"),
                    priv->user, priv->host, err->message);
             printf(_("Falling back\n"));
@@ -384,10 +383,8 @@ libbalsa_server_load_config(LibBalsaServer * server)
        }
 #endif
     }
-    if(priv->passwd && priv->passwd[0] == '\0') {
-       libbalsa_free_password(priv->passwd);
-       priv->passwd = NULL;
-    }
+    if (priv->passwd && priv->passwd[0] == '\0')
+        g_clear_pointer(&priv->passwd, libbalsa_free_password);
 
     priv->client_cert = libbalsa_conf_get_bool("NeedClientCert=false");
     priv->cert_file = libbalsa_conf_get_string("UserCertificateFile");
@@ -398,8 +395,7 @@ libbalsa_server_load_config(LibBalsaServer * server)
         g_free(priv->cert_passphrase);
         priv->cert_passphrase = tmp;
     } else {
-       g_free(priv->cert_passphrase);
-       priv->cert_passphrase = NULL;
+        g_clear_pointer(&priv->cert_passphrase, g_free);
     }
 }
 
diff --git a/libnetclient/net-client-pop.c b/libnetclient/net-client-pop.c
index 1c35b36c6..94bc569e2 100644
--- a/libnetclient/net-client-pop.c
+++ b/libnetclient/net-client-pop.c
@@ -655,8 +655,7 @@ net_client_pop_auth_gssapi(NetClientPop *client, const gchar *user, GError **err
 
                do {
                        state = net_client_gss_auth_step(gss_ctx, input_token, &output_token, error);
-                       g_free(input_token);
-                       input_token = NULL;
+                        g_clear_pointer(&input_token, g_free);
                        if (state >= 0) {
                                if (initial) {
                                        /* split the initial auth command as the initial-response argument 
will typically exceed the 255-octet limit on
diff --git a/libnetclient/net-client-siobuf.c b/libnetclient/net-client-siobuf.c
index ea82b9a2b..69a5d184e 100644
--- a/libnetclient/net-client-siobuf.c
+++ b/libnetclient/net-client-siobuf.c
@@ -43,8 +43,7 @@ net_client_siobuf_new(const gchar *host, guint16 port)
        client = NET_CLIENT_SIOBUF(g_object_new(NET_CLIENT_SIOBUF_TYPE, NULL));
        if (client != NULL) {
                if (!net_client_configure(NET_CLIENT(client), host, port, 0, NULL)) {
-                       g_object_unref(G_OBJECT(client));
-                       client = NULL;
+                        g_clear_object(&client);
                } else {
                        client->priv->buffer = g_string_sized_new(1024U);
                        client->priv->read_ptr = NULL;
diff --git a/libnetclient/net-client-smtp.c b/libnetclient/net-client-smtp.c
index 9fa1f07fe..f9cda639e 100644
--- a/libnetclient/net-client-smtp.c
+++ b/libnetclient/net-client-smtp.c
@@ -90,8 +90,7 @@ net_client_smtp_new(const gchar *host, guint16 port, NetClientCryptMode crypt_mo
         priv = net_client_smtp_get_instance_private(client);
        if (client != NULL) {
                if (!net_client_configure(NET_CLIENT(client), host, port, MAX_SMTP_LINE_LEN, NULL)) {
-                       g_object_unref(G_OBJECT(client));
-                       client = NULL;
+                        g_clear_object(&client);
                } else {
                        priv->crypt_mode = crypt_mode;
                }
@@ -513,8 +512,7 @@ net_client_smtp_auth_gssapi(NetClientSmtp *client, const gchar *user, GError **e
 
                do {
                        state = net_client_gss_auth_step(gss_ctx, input_token, &output_token, error);
-                       g_free(input_token);
-                       input_token = NULL;
+                        g_clear_pointer(&input_token, g_free);
                        if (state >= 0) {
                                if (initial) {
                                        result = net_client_smtp_execute(client, "AUTH GSSAPI %s", 
&input_token, error, output_token);
diff --git a/libnetclient/net-client-utils.c b/libnetclient/net-client-utils.c
index 83c9641ad..987181f93 100644
--- a/libnetclient/net-client-utils.c
+++ b/libnetclient/net-client-utils.c
@@ -154,8 +154,7 @@ net_client_gss_ctx_new(const gchar *service, const gchar *host, const gchar *use
        g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_GSSAPI, _("importing GSS service 
name %s failed: %s"),
                service_str, gss_err);
        g_free(gss_err);
-       g_free(gss_ctx);
-       gss_ctx = NULL;
+        g_clear_pointer(&gss_ctx, g_free);
     } else {
        /* configure the context according to RFC 4752, Sect. 3.1 */
        gss_ctx->req_flags = GSS_C_INTEG_FLAG + GSS_C_MUTUAL_FLAG + GSS_C_SEQUENCE_FLAG + GSS_C_CONF_FLAG;
diff --git a/libnetclient/net-client.c b/libnetclient/net-client.c
index 459070947..3af38c1c0 100644
--- a/libnetclient/net-client.c
+++ b/libnetclient/net-client.c
@@ -501,8 +501,7 @@ net_client_start_tls(NetClient *client, GError **error)
                                priv->ostream = g_io_stream_get_output_stream(G_IO_STREAM(priv->tls_conn));
                                g_debug("connection is encrypted");
                        } else {
-                               g_object_unref(G_OBJECT(priv->tls_conn));
-                               priv->tls_conn = NULL;
+                                g_clear_object(&priv->tls_conn);
                        }
                }
        }
diff --git a/src/ab-main.c b/src/ab-main.c
index 428fcebe7..0fb06e935 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -471,18 +471,16 @@ file_delete_activated(GSimpleAction * action,
     /* Leave a NULL item in the address book list, to avoid changing the
      * positions of the other books. */
     list = g_list_find(contacts_app.address_book_list, address_book);
-    list->data = NULL;
-    g_object_unref(address_book);
+    g_clear_object(&list->data);
 
     for (list = contacts_app.address_book_list; list; list = list->next)
-        if ((address_book = list->data) != NULL)
+        if (list->data != NULL)
             break;
 
-    if (!list)
-        return;
-
-    contacts_app.address_book = list->data;
-    set_address_book_menu_items();
+    if (list != NULL) {
+        contacts_app.address_book = list->data;
+        set_address_book_menu_items();
+    }
 }
 
 static void
diff --git a/src/balsa-icons.c b/src/balsa-icons.c
index be0e83251..cf402fcb3 100644
--- a/src/balsa-icons.c
+++ b/src/balsa-icons.c
@@ -188,10 +188,7 @@ balsa_register_pixmaps(void)
 void
 balsa_unregister_pixmaps(void)
 {
-    if (balsa_icon_table) {
-        g_hash_table_destroy(balsa_icon_table);
-        balsa_icon_table = NULL;
-    }
+    g_clear_pointer(&balsa_icon_table, g_hash_table_destroy);
 }
 
 void
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 2b787bbc5..f72f4a664 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2567,11 +2567,10 @@ pipe_in_watch(GIOChannel  *channel,
 
     rc = pipe->message_length > pipe->chars_written;
     if (!rc) {
-        g_io_channel_unref(pipe->in_channel);
-        pipe->in_channel = NULL;
-        g_source_remove(pipe->in_source);
-        pipe->in_source = 0;
+        g_clear_pointer(&pipe->in_channel, g_io_channel_unref);
+        libbalsa_clear_source_id(&pipe->in_source);
     }
+
     return rc;
 }
 
@@ -2937,8 +2936,7 @@ balsa_index_ensure_visible(BalsaIndex *index)
         if (gtk_tree_view_get_path_at_pos(tree_view, rect.x, rect.y, &path,
                                           NULL, NULL, NULL)) {
             /* We have a message in the view, so we do nothing. */
-            gtk_tree_path_free(path);
-            path = NULL;
+            g_clear_pointer(&path, gtk_tree_path_free);
         } else {
             /* Scroll to the last message. */
             GtkTreeModel *model;
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 85adc1826..a59c6d0ef 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -821,8 +821,7 @@ balsa_message_destroy(GObject * object)
 
     if (bm->treeview) {
         balsa_message_set(bm, NULL, 0);
-        gtk_widget_destroy(bm->treeview);
-        bm->treeview = NULL;
+        g_clear_pointer(&bm->treeview, gtk_widget_destroy);
     }
 
     g_clear_pointer(&bm->save_all_list, g_list_free);
@@ -1107,8 +1106,7 @@ balsa_message_set(BalsaMessage * bm, LibBalsaMailbox * mailbox, guint msgno)
     select_part(bm, NULL);
     if (bm->message != NULL) {
         libbalsa_message_body_unref(bm->message);
-        g_object_unref(bm->message);
-        bm->message = NULL;
+        g_clear_object(&bm->message);
     }
 
     if (mailbox == NULL || msgno == 0) {
@@ -1134,8 +1132,7 @@ balsa_message_set(BalsaMessage * bm, LibBalsaMailbox * mailbox, guint msgno)
     is_new = LIBBALSA_MESSAGE_IS_UNREAD(message);
     if(!libbalsa_message_body_ref(message, TRUE, TRUE)) {
        libbalsa_mailbox_check(mailbox);
-        g_object_unref(bm->message);
-        bm->message = NULL;
+        g_clear_object(&bm->message);
        balsa_information(LIBBALSA_INFORMATION_WARNING,
                           _("Could not access message %u "
                             "in mailbox “%s”."),
@@ -2221,8 +2218,7 @@ hide_all_parts(BalsaMessage * bm)
                               gtk_tree_hide_func, bm);
        gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
                                        (GTK_TREE_VIEW(bm->treeview)));
-        g_object_unref(bm->current_part);
-       bm->current_part = NULL;
+        g_clear_object(&bm->current_part);
     }
 
     gtk_container_foreach(GTK_CONTAINER(balsa_mime_widget_get_container(bm->bm_widget)),
@@ -3058,8 +3054,7 @@ libbalsa_msg_part_2440(LibBalsaMessage * message, LibBalsaMessageBody * body,
        if (sig_res == GPG_ERR_NO_ERROR) {
            /* decrypting may change the charset, so be sure to use the one
               GMimePart reports */
-           g_free(body->charset);
-           body->charset = NULL;
+            g_clear_pointer(&body->charset, g_free);
        }
     }
     libbalsa_mailbox_unlock_store(mailbox);
diff --git a/src/balsa-mime-widget-crypto.c b/src/balsa-mime-widget-crypto.c
index 246088f6f..b7ee09d48 100644
--- a/src/balsa-mime-widget-crypto.c
+++ b/src/balsa-mime-widget-crypto.c
@@ -93,8 +93,7 @@ balsa_mime_widget_new_pgpkey(BalsaMessage        *bm,
             g_clear_error(&err);
             g_object_ref_sink(box);
             g_object_unref(box);
-            g_object_unref(mw);
-            mw = NULL;
+            g_clear_object(&mw);
         }
        g_free(body_buf);
     }
diff --git a/src/balsa-print-object-header.c b/src/balsa-print-object-header.c
index 00c43237b..6b71f1391 100644
--- a/src/balsa-print-object-header.c
+++ b/src/balsa-print-object-header.c
@@ -276,8 +276,7 @@ balsa_print_object_header_new_real(GList                  *list,
         poh->p_label_width  = p_label_width;
         poh->p_layout_width = p_layout_width;
         if (face != NULL) {
-            poh->face = face;
-            face      = NULL;
+            poh->face = g_steal_pointer(&face);
 
             if (this_chunk->next == NULL) {
                 gint p_height;
diff --git a/src/compose-window.c b/src/compose-window.c
index 2a333bb31..610a25d0e 100644
--- a/src/compose-window.c
+++ b/src/compose-window.c
@@ -3206,8 +3206,7 @@ sw_can_convert(const gchar *string,
                   &bytes_read, &bytes_written, &err);
     if (err) {
         g_error_free(err);
-        g_free(s);
-        s = NULL;
+        g_clear_pointer(&s, g_free);
     }
 
     if (result)
@@ -5295,8 +5294,8 @@ compose_window2message(BalsaComposeWindow *compose_window)
                             /* Translators: please do not translate Face. */
                             _("Could not load X-Face header file %s: %s"));
 
-    libbalsa_message_set_references(message, compose_window->references);
-    compose_window->references = NULL; /* steal it */
+    libbalsa_message_set_references(message,
+                                    g_steal_pointer(&compose_window->references));
 
     if (compose_window->in_reply_to != NULL) {
         libbalsa_message_set_in_reply_to(message,
diff --git a/src/filter-edit-callbacks.c b/src/filter-edit-callbacks.c
index c7f4cac62..020a83a85 100644
--- a/src/filter-edit-callbacks.c
+++ b/src/filter-edit-callbacks.c
@@ -1685,9 +1685,7 @@ change_filter_name(gchar * old_name,gchar * new_name)
             return;
         }
 
-        if (new_name)
-            p->new_name=g_strdup(new_name);
-        else p->new_name=NULL;
+        p->new_name = g_strdup(new_name);
     }
 }
 
diff --git a/src/folder-conf.c b/src/folder-conf.c
index a9ce9e396..da5aade36 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -116,8 +116,7 @@ folder_conf_response(GtkDialog * dialog, int response,
             break;
         /* ...or fall over */
     default:
-        gtk_widget_destroy(GTK_WIDGET(cdd->dialog));
-        cdd->dialog = NULL;
+        g_clear_pointer(&cdd->dialog, gtk_widget_destroy);
         if (cdd->mbnode) {
             /* Clearing the data signifies that the dialog has been
              * destroyed. It also triggers a call to
diff --git a/src/main-window.c b/src/main-window.c
index 0da3413fe..8a367c28f 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -4007,8 +4007,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
            return;
        cnd->type = CONDITION_STRING;
 
-       libbalsa_mailbox_search_iter_unref(search_iter);
-       search_iter = NULL;
+        g_clear_pointer(&search_iter, libbalsa_mailbox_search_iter_unref);
 
         if(ok == FIND_RESPONSE_FILTER) {
             LibBalsaMailbox *mailbox =
@@ -4018,8 +4017,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
             res = libbalsa_condition_new_bool_ptr(FALSE, CONDITION_AND,
                                                   filter, cnd);
             libbalsa_condition_unref(filter);
-            libbalsa_condition_unref(cnd);
-            cnd = NULL;
+            g_clear_pointer(&cnd, libbalsa_condition_unref);
 
             if (libbalsa_mailbox_set_view_filter(mailbox, res, TRUE))
                 balsa_index_ensure_visible(BALSA_INDEX(bindex));
diff --git a/src/main.c b/src/main.c
index 0ec803253..4099da907 100644
--- a/src/main.c
+++ b/src/main.c
@@ -224,8 +224,7 @@ balsa_check_open_mailboxes(void)
     gchar **urls;
 
     join = g_strjoinv(";", cmd_line_open_mailboxes);
-    g_strfreev(cmd_line_open_mailboxes);
-    cmd_line_open_mailboxes = NULL;
+    g_clear_pointer(&cmd_line_open_mailboxes, g_strfreev);
 
     urls = g_strsplit(join, ";", 20);
     g_free(join);
@@ -275,8 +274,7 @@ scan_mailboxes_idle_cb()
         gchar **p;
 
         join = g_strjoinv(";", cmd_line_open_mailboxes);
-        g_strfreev(cmd_line_open_mailboxes);
-        cmd_line_open_mailboxes = NULL;
+        g_clear_pointer(&cmd_line_open_mailboxes, g_strfreev);
 
         urls = g_strsplit(join, ";", 20);
         g_free(join);
@@ -455,16 +453,12 @@ balsa_check_open_compose_window(void)
                                            balsa_compose_window_set_field, compose_window);
             else
                 balsa_compose_window_set_field(compose_window, "to", opt_compose_email);
-            g_free(opt_compose_email);
-            opt_compose_email = NULL;
+            g_clear_pointer(&opt_compose_email, g_free);
         }
 
-        if (opt_attach_list) {
-            for (attach = opt_attach_list; *attach; ++attach)
-                add_attachment(compose_window, *attach, FALSE, NULL);
-            g_strfreev(opt_attach_list);
-            opt_attach_list = NULL;
-        }
+        for (attach = opt_attach_list; attach != NULL; ++attach)
+            add_attachment(compose_window, *attach, FALSE, NULL);
+        g_clear_pointer(&opt_attach_list, g_strfreev);
 
         return TRUE;
     }
@@ -724,8 +718,7 @@ parse_options(int                       argc,
             /* process remaining_args[i] here */
             /* we do nothing for now */
         }
-        g_strfreev(remaining_args);
-        remaining_args = NULL;
+        g_clear_pointer(&remaining_args, g_strfreev);
     }
 
     g_option_context_free(context);
diff --git a/src/pref-manager.c b/src/pref-manager.c
index b3d6e7703..5247a10ef 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -316,8 +316,7 @@ pm_selection_changed(GtkTreeSelection * selection, gpointer user_data)
 static void
 destroy_pref_window_cb(void)
 {
-    g_free(pui);
-    pui = NULL;
+    g_clear_pointer(&pui, g_free);
     already_open = FALSE;
 }
 
diff --git a/src/spell-check.c b/src/spell-check.c
index fecec3896..2cd897e34 100644
--- a/src/spell-check.c
+++ b/src/spell-check.c
@@ -899,8 +899,7 @@ spch_finish(BalsaSpellCheck *spell_check,
                                      spell_check->dict);
             spell_check->dict = NULL;
         }
-        enchant_broker_free(spell_check->broker);
-        spell_check->broker = NULL;
+        g_clear_pointer(&spell_check->broker, enchant_broker_free);
     }
 
     if (balsa_app.debug)


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