# HG changeset patch
# Node ID a542968a4cb5
# Parent  9f89ed3c6465
diff --git a/finch/gntaccount.c b/finch/gntaccount.c
--- a/finch/gntaccount.c
+++ b/finch/gntaccount.c
@@ -380,11 +380,7 @@ add_account_options(AccountEditDialog *d
 		gnt_box_set_fill(GNT_BOX(vbox), TRUE);
 	}
 
-	if (dialog->protocol_entries)
-	{
-		g_list_free(dialog->protocol_entries);
-		dialog->protocol_entries = NULL;
-	}
+	g_clear_list(&dialog->protocol_entries, NULL);
 
 	vbox = dialog->protocols;
 
@@ -949,8 +945,6 @@ finch_accounts_init(void)
 }
 
 void
-finch_accounts_uninit(void)
-{
-	if (accounts.window)
-		gnt_widget_destroy(accounts.window);
+finch_accounts_uninit(void) {
+	g_clear_pointer(&accounts.window, gnt_widget_destroy);
 }
diff --git a/finch/gntblist.c b/finch/gntblist.c
--- a/finch/gntblist.c
+++ b/finch/gntblist.c
@@ -1844,13 +1844,11 @@ reset_blist_window(G_GNUC_UNUSED GntWidg
 	if (ggblist->typing)
 		g_source_remove(ggblist->typing);
 	remove_peripherals(ggblist);
-	if (ggblist->tagged)
-		g_list_free(ggblist->tagged);
+	g_clear_list(&ggblist->tagged, NULL);
 
 	if (ggblist->new_group_timeout)
 		g_source_remove(ggblist->new_group_timeout);
-	if (ggblist->new_group)
-		g_list_free(ggblist->new_group);
+	g_clear_list(&ggblist->new_group, NULL);
 
 	ggblist = NULL;
 }
diff --git a/finch/gntconn.c b/finch/gntconn.c
--- a/finch/gntconn.c
+++ b/finch/gntconn.c
@@ -145,5 +145,5 @@ finch_connections_uninit(void)
 	g_signal_handlers_disconnect_by_func(manager,
 	                                     G_CALLBACK(account_removed_cb), NULL);
 
-	g_hash_table_destroy(hash);
+	g_clear_pointer(&hash, g_hash_table_destroy);
 }
diff --git a/finch/gntnotify.c b/finch/gntnotify.c
--- a/finch/gntnotify.c
+++ b/finch/gntnotify.c
@@ -424,9 +424,6 @@ finch_notify_init(void)
 }
 
 void
-finch_notify_uninit(void)
-{
-	g_hash_table_destroy(userinfo);
+finch_notify_uninit(void) {
+	g_clear_pointer(&userinfo, g_hash_table_destroy);
 }
-
-
diff --git a/finch/gntprefs.c b/finch/gntprefs.c
--- a/finch/gntprefs.c
+++ b/finch/gntprefs.c
@@ -229,8 +229,7 @@ static Prefs credentials[] =
 static void
 free_strings(void)
 {
-	g_list_free_full(pref_request.freestrings, g_free);
-	pref_request.freestrings = NULL;
+	g_clear_list(&pref_request.freestrings, g_free);
 	pref_request.showing = FALSE;
 }
 
diff --git a/finch/plugins/gnttinyurl/gnttinyurl.c b/finch/plugins/gnttinyurl/gnttinyurl.c
--- a/finch/plugins/gnttinyurl/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl/gnttinyurl.c
@@ -552,8 +552,7 @@ tiny_url_unload(GPluginPlugin *plugin, G
 	soup_session_abort(session);
 	g_clear_object(&session);
 
-	g_hash_table_destroy(tinyurl_cache);
-	tinyurl_cache = NULL;
+	g_clear_pointer(&tinyurl_cache, g_hash_table_destroy);
 
 	return TRUE;
 }
diff --git a/finch/plugins/grouping/grouping.c b/finch/plugins/grouping/grouping.c
--- a/finch/plugins/grouping/grouping.c
+++ b/finch/plugins/grouping/grouping.c
@@ -250,8 +250,7 @@ nested_group_init(void)
 static gboolean
 nested_group_uninit(void)
 {
-	g_hash_table_destroy(groups);
-	groups = NULL;
+	g_clear_pointer(&groups, g_hash_table_destroy);
 	return TRUE;
 }
 
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -1138,9 +1138,7 @@ purple_buddy_icons_uninit(void)
 	g_hash_table_destroy(icon_data_cache);
 	g_hash_table_destroy(icon_file_cache);
 	g_hash_table_destroy(pointer_icon_cache);
-	g_free(cache_dir);
-
-	cache_dir = NULL;
+	g_clear_pointer(&cache_dir, g_free);
 }
 
 GType
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -2179,16 +2179,12 @@ purple_blist_uninit(void)
 
 	purple_debug_info("buddylist", "Destroying");
 
-	g_hash_table_destroy(buddies_cache);
-	g_hash_table_destroy(groups_cache);
-
-	buddies_cache = NULL;
-	groups_cache = NULL;
+	g_clear_pointer(&buddies_cache, g_hash_table_destroy);
+	g_clear_pointer(&groups_cache, g_hash_table_destroy);
 
 	g_clear_object(&purplebuddylist);
 
-	g_free(localized_default_group_name);
-	localized_default_group_name = NULL;
+	g_clear_pointer(&localized_default_group_name, g_free);
 
 	purple_signals_disconnect_by_handle(purple_blist_get_handle());
 	purple_signals_unregister_by_instance(purple_blist_get_handle());
diff --git a/libpurple/cmds.c b/libpurple/cmds.c
--- a/libpurple/cmds.c
+++ b/libpurple/cmds.c
@@ -392,7 +392,6 @@ void purple_cmds_uninit(void)
 {
 	purple_signals_unregister_by_instance(purple_cmds_get_handle());
 
-	g_list_free_full(cmds, (GDestroyNotify)purple_cmd_free);
-	cmds = NULL;
+	g_clear_list(&cmds, (GDestroyNotify)purple_cmd_free);
 }
 
diff --git a/libpurple/image-store.c b/libpurple/image-store.c
--- a/libpurple/image-store.c
+++ b/libpurple/image-store.c
@@ -219,13 +219,10 @@ void
 void
 _purple_image_store_uninit(void)
 {
-	g_slist_free_full(perm_images, g_object_unref);
-	perm_images = NULL;
+	g_clear_slist(&perm_images, g_object_unref);
 
 	g_hash_table_foreach(temp_images, cancel_temporary, NULL);
-	g_hash_table_destroy(temp_images);
-	temp_images = NULL;
+	g_clear_pointer(&temp_images, g_hash_table_destroy);
 
-	g_hash_table_destroy(id_to_image);
-	id_to_image = NULL;
+	g_clear_pointer(&id_to_image, g_hash_table_destroy);
 }
diff --git a/libpurple/mediamanager.c b/libpurple/mediamanager.c
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -201,10 +201,8 @@ purple_media_manager_finalize (GObject *
 	g_list_free_full(priv->private_medias, g_object_unref);
 	g_list_free_full(priv->elements, g_object_unref);
 	g_clear_pointer(&priv->video_caps, gst_caps_unref);
-	if (priv->appdata_info) {
-		g_list_free_full(priv->appdata_info,
-		                 (GDestroyNotify)free_appdata_info_locked);
-	}
+	g_clear_list(&priv->appdata_info,
+	             (GDestroyNotify)free_appdata_info_locked);
 	g_mutex_clear (&priv->appdata_mutex);
 	if (priv->device_monitor) {
 		gst_device_monitor_stop(priv->device_monitor);
diff --git a/libpurple/plugins/idle/idle.c b/libpurple/plugins/idle/idle.c
--- a/libpurple/plugins/idle/idle.c
+++ b/libpurple/plugins/idle/idle.c
@@ -256,8 +256,7 @@ purple_idle_unset_all_accounts_idle_time
 	/* freeing the list here will cause segfaults if the user idles an account
 	 * after the list is freed */
 	g_list_foreach(idled_accts, (GFunc)set_idle_time, GINT_TO_POINTER(0));
-	g_list_free(idled_accts);
-	idled_accts = NULL;
+	g_clear_list(&idled_accts, NULL);
 }
 
 /******************************************************************************
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -923,8 +923,7 @@ purple_prefs_set_string_list(const char 
 			return;
 		}
 
-		g_list_free_full(pref->value.stringlist, g_free);
-		pref->value.stringlist = NULL;
+		g_clear_list(&pref->value.stringlist, g_free);
 
 		for(tmp = value; tmp; tmp = tmp->next) {
 			if(tmp->data != NULL && !g_utf8_validate(tmp->data, -1, NULL)) {
@@ -1489,6 +1488,5 @@ purple_prefs_uninit(void)
 
 	prefs_loaded = FALSE;
 	purple_prefs_destroy();
-	g_hash_table_destroy(prefs_hash);
-	prefs_hash = NULL;
+	g_clear_pointer(&prefs_hash, g_hash_table_destroy);
 }
diff --git a/libpurple/protocols/facebook/facebook.c b/libpurple/protocols/facebook/facebook.c
--- a/libpurple/protocols/facebook/facebook.c
+++ b/libpurple/protocols/facebook/facebook.c
@@ -1672,7 +1672,7 @@ fb_cmds_unregister_free(gpointer data)
 static void
 fb_cmds_unregister(void)
 {
-	g_slist_free_full(fb_cmds, fb_cmds_unregister_free);
+	g_clear_slist(&fb_cmds, fb_cmds_unregister_free);
 }
 
 static GPluginPluginInfo *
diff --git a/libpurple/protocols/gg/chat.c b/libpurple/protocols/gg/chat.c
--- a/libpurple/protocols/gg/chat.c
+++ b/libpurple/protocols/gg/chat.c
@@ -197,8 +197,7 @@ void ggp_chat_got_event(PurpleConnection
 			ggp_chat_join_id(gc, *id_p);
 			it = g_slist_next(it);
 		}
-		g_slist_free_full(sdata->pending_joins, g_free);
-		sdata->pending_joins = NULL;
+		g_clear_slist(&sdata->pending_joins, g_free);
 	} else if (ev->type == GG_EVENT_CHAT_INFO_UPDATE) {
 		const struct gg_event_chat_info_update *eciu =
 			&ev->event.chat_info_update;
diff --git a/libpurple/protocols/gg/message-prpl.c b/libpurple/protocols/gg/message-prpl.c
--- a/libpurple/protocols/gg/message-prpl.c
+++ b/libpurple/protocols/gg/message-prpl.c
@@ -590,8 +590,7 @@ ggp_message_format_to_gg(PurpleConversat
 				font_new->color = color;
 			}
 
-			if (styles)
-				g_hash_table_destroy(styles);
+			g_clear_pointer(&styles, g_hash_table_destroy);
 			g_hash_table_destroy(attribs);
 		}
 		else if ((tag == GGP_HTML_TAG_FONT || tag == GGP_HTML_TAG_SPAN
diff --git a/libpurple/protocols/gg/roster.c b/libpurple/protocols/gg/roster.c
--- a/libpurple/protocols/gg/roster.c
+++ b/libpurple/protocols/gg/roster.c
@@ -148,16 +148,11 @@ static void ggp_roster_content_free(ggp_
 {
 	if (content == NULL)
 		return;
-	if (content->xml)
-		purple_xmlnode_free(content->xml);
-	if (content->contact_nodes)
-		g_hash_table_destroy(content->contact_nodes);
-	if (content->group_nodes)
-		g_hash_table_destroy(content->group_nodes);
-	if (content->group_ids)
-		g_hash_table_destroy(content->group_ids);
-	if (content->group_names)
-		g_hash_table_destroy(content->group_names);
+	g_clear_pointer(&content->xml, purple_xmlnode_free);
+	g_clear_pointer(&content->contact_nodes, g_hash_table_destroy);
+	g_clear_pointer(&content->group_nodes, g_hash_table_destroy);
+	g_clear_pointer(&content->group_ids, g_hash_table_destroy);
+	g_clear_pointer(&content->group_names, g_hash_table_destroy);
 	g_free(content->bots_group_id);
 	g_free(content);
 }
@@ -1062,8 +1057,7 @@ static void ggp_roster_reply_ack(PurpleC
 			ggp_roster_set_synchronized(gc, buddy, FALSE);
 	}
 
-	g_list_free_full(rdata->sent_updates, ggp_roster_change_free);
-	rdata->sent_updates = NULL;
+	g_clear_list(&rdata->sent_updates, ggp_roster_change_free);
 
 	/* bump roster version or update it, if needed */
 	g_return_if_fail(content != NULL);
diff --git a/libpurple/protocols/gg/servconn.c b/libpurple/protocols/gg/servconn.c
--- a/libpurple/protocols/gg/servconn.c
+++ b/libpurple/protocols/gg/servconn.c
@@ -65,7 +65,7 @@ void ggp_servconn_setup(PurpleAccountOpt
 
 void ggp_servconn_cleanup(void)
 {
-	g_list_free_full(global_data.server_history, &g_free);
+	g_clear_list(&global_data.server_history, g_free);
 }
 
 void ggp_servconn_add_server(const gchar *server)
diff --git a/libpurple/protocols/irc/parse.c b/libpurple/protocols/irc/parse.c
--- a/libpurple/protocols/irc/parse.c
+++ b/libpurple/protocols/irc/parse.c
@@ -240,7 +240,7 @@ void irc_register_commands(void)
 
 void irc_unregister_commands(void)
 {
-	g_slist_free_full(cmds, (GDestroyNotify)(gpointer)purple_cmd_unregister);
+	g_clear_slist(&cmds, (GDestroyNotify)(gpointer)purple_cmd_unregister);
 }
 
 static char *irc_send_convert(struct irc_conn *irc, const char *string)
diff --git a/libpurple/protocols/jabber/adhoccommands.c b/libpurple/protocols/jabber/adhoccommands.c
--- a/libpurple/protocols/jabber/adhoccommands.c
+++ b/libpurple/protocols/jabber/adhoccommands.c
@@ -73,8 +73,7 @@ jabber_adhoc_got_buddy_list(JabberStream
 		return;
 
 	/* since the list we just received is complete, wipe the old one */
-	g_list_free_full(jbr->commands, (GDestroyNotify)jabber_adhoc_commands_free);
-	jbr->commands = NULL;
+	g_clear_list(&jbr->commands, (GDestroyNotify)jabber_adhoc_commands_free);
 
 	for(item = query->child; item; item = item->next) {
 		JabberAdHocCommands *cmd;
@@ -248,8 +247,7 @@ jabber_adhoc_got_server_list(JabberStrea
 		return;
 
 	/* clean current list (just in case there is one) */
-	g_list_free_full(js->commands, (GDestroyNotify)jabber_adhoc_commands_free);
-	js->commands = NULL;
+	g_clear_list(&js->commands, (GDestroyNotify)jabber_adhoc_commands_free);
 
 	/* re-fill list */
 	for(item = query->child; item; item = item->next) {
diff --git a/libpurple/protocols/jabber/auth.c b/libpurple/protocols/jabber/auth.c
--- a/libpurple/protocols/jabber/auth.c
+++ b/libpurple/protocols/jabber/auth.c
@@ -553,6 +553,5 @@ void jabber_auth_init(void)
 
 void jabber_auth_uninit(void)
 {
-	g_slist_free(auth_mechs);
-	auth_mechs = NULL;
+	g_clear_slist(&auth_mechs, NULL);
 }
diff --git a/libpurple/protocols/jabber/bosh.c b/libpurple/protocols/jabber/bosh.c
--- a/libpurple/protocols/jabber/bosh.c
+++ b/libpurple/protocols/jabber/bosh.c
@@ -84,8 +84,7 @@ jabber_bosh_init(void)
 
 void jabber_bosh_uninit(void)
 {
-	g_free(jabber_bosh_useragent);
-	jabber_bosh_useragent = NULL;
+	g_clear_pointer(&jabber_bosh_useragent, g_free);
 }
 
 PurpleJabberBOSHConnection*
diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c
--- a/libpurple/protocols/jabber/buddy.c
+++ b/libpurple/protocols/jabber/buddy.c
@@ -1446,8 +1446,8 @@ jabber_time_parse(G_GNUC_UNUSED JabberSt
 
 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js)
 {
-	g_slist_free_full(js->pending_buddy_info_requests, (GDestroyNotify)jabber_buddy_info_destroy);
-	js->pending_buddy_info_requests = NULL;
+	g_clear_slist(&js->pending_buddy_info_requests,
+	              (GDestroyNotify)jabber_buddy_info_destroy);
 }
 
 static gboolean jabber_buddy_get_info_timeout(gpointer data)
diff --git a/libpurple/protocols/jabber/caps.c b/libpurple/protocols/jabber/caps.c
--- a/libpurple/protocols/jabber/caps.c
+++ b/libpurple/protocols/jabber/caps.c
@@ -207,8 +207,7 @@ void jabber_caps_uninit(void)
 		save_timer = 0;
 		do_jabber_caps_store(NULL);
 	}
-	g_hash_table_destroy(capstable);
-	capstable = NULL;
+	g_clear_pointer(&capstable, g_hash_table_destroy);
 }
 
 typedef struct {
diff --git a/libpurple/protocols/jabber/data.c b/libpurple/protocols/jabber/data.c
--- a/libpurple/protocols/jabber/data.c
+++ b/libpurple/protocols/jabber/data.c
@@ -468,8 +468,7 @@ jabber_data_uninit(void)
 {
 	if (purple_debug_is_verbose())
 		purple_debug_info("jabber", "destroying hash tables for data objects");
-	g_hash_table_destroy(local_data_by_alt);
-	g_hash_table_destroy(local_data_by_cid);
-	g_hash_table_destroy(remote_data_by_cid);
-	local_data_by_alt = local_data_by_cid = remote_data_by_cid = NULL;
+	g_clear_pointer(&local_data_by_alt, g_hash_table_destroy);
+	g_clear_pointer(&local_data_by_cid, g_hash_table_destroy);
+	g_clear_pointer(&remote_data_by_cid, g_hash_table_destroy);
 }
diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -462,8 +462,7 @@ jabber_disco_server_items_result_cb(Jabb
 	if (type == JABBER_IQ_ERROR)
 		return;
 
-	g_list_free_full(js->chat_servers, g_free);
-	js->chat_servers = NULL;
+	g_clear_list(&js->chat_servers, g_free);
 
 	query = purple_xmlnode_get_child(packet, "query");
 
diff --git a/libpurple/protocols/jabber/ibb.c b/libpurple/protocols/jabber/ibb.c
--- a/libpurple/protocols/jabber/ibb.c
+++ b/libpurple/protocols/jabber/ibb.c
@@ -509,9 +509,6 @@ jabber_ibb_init(void)
 void
 jabber_ibb_uninit(void)
 {
-	g_hash_table_destroy(jabber_ibb_sessions);
-	g_list_free(open_handlers);
-	jabber_ibb_sessions = NULL;
-	open_handlers = NULL;
+	g_clear_pointer(&jabber_ibb_sessions, g_hash_table_destroy);
+	g_clear_list(&open_handlers, NULL);
 }
-
diff --git a/libpurple/protocols/jabber/iq.c b/libpurple/protocols/jabber/iq.c
--- a/libpurple/protocols/jabber/iq.c
+++ b/libpurple/protocols/jabber/iq.c
@@ -557,7 +557,6 @@ void jabber_iq_init(void)
 
 void jabber_iq_uninit(void)
 {
-	g_hash_table_destroy(iq_handlers);
-	g_hash_table_destroy(signal_iq_handlers);
-	iq_handlers = signal_iq_handlers = NULL;
+	g_clear_pointer(&iq_handlers, g_hash_table_destroy);
+	g_clear_pointer(&signal_iq_handlers, g_hash_table_destroy);
 }
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -1025,12 +1025,9 @@ jabber_close(G_GNUC_UNUSED PurpleProtoco
 
 	jabber_parser_free(js);
 
-	if(js->iq_callbacks)
-		g_hash_table_destroy(js->iq_callbacks);
-	if(js->buddies)
-		g_hash_table_destroy(js->buddies);
-	if(js->chats)
-		g_hash_table_destroy(js->chats);
+	g_clear_pointer(&js->iq_callbacks, g_hash_table_destroy);
+	g_clear_pointer(&js->buddies, g_hash_table_destroy);
+	g_clear_pointer(&js->chats, g_hash_table_destroy);
 
 	g_list_free_full(js->chat_servers, g_free);
 
@@ -1042,8 +1039,7 @@ jabber_close(G_GNUC_UNUSED PurpleProtoco
 	}
 
 	g_free(js->stream_id);
-	if(js->user)
-		jabber_id_free(js->user);
+	g_clear_pointer(&js->user, jabber_id_free);
 	g_free(js->initial_avatar_hash);
 	g_free(js->avatar_hash);
 	g_free(js->caps_hash);
@@ -2620,9 +2616,7 @@ jabber_get_media_caps(G_GNUC_UNUSED Purp
 		total |= caps;
 	}
 
-	if (specific) {
-		g_list_free(specific);
-	}
+	g_clear_list(&specific, NULL);
 
 	return total;
 }
@@ -2980,11 +2974,10 @@ jabber_do_uninit(void)
 			G_CALLBACK(jabber_caps_broadcast_change), NULL);
 
 	jabber_auth_uninit();
-	g_list_free_full(jabber_features, (GDestroyNotify)jabber_feature_free);
-	g_list_free_full(jabber_identities, (GDestroyNotify)jabber_identity_free);
-
-	g_hash_table_destroy(jabber_cmds);
-	jabber_cmds = NULL;
+	g_clear_list(&jabber_features, (GDestroyNotify)jabber_feature_free);
+	g_clear_list(&jabber_identities, (GDestroyNotify)jabber_identity_free);
+
+	g_clear_pointer(&jabber_cmds, g_hash_table_destroy);
 }
 
 static void jabber_init_protocol(PurpleProtocol *protocol)
diff --git a/libpurple/protocols/jabber/jingle/rtp.c b/libpurple/protocols/jabber/jingle/rtp.c
--- a/libpurple/protocols/jabber/jingle/rtp.c
+++ b/libpurple/protocols/jabber/jingle/rtp.c
@@ -821,8 +821,7 @@ jingle_rtp_get_media(JingleSession *sess
 			break;
 		}
 	}
-	if (iter != NULL)
-		g_list_free(iter);
+	g_clear_list(&iter, NULL);
 
 	return media;
 }
diff --git a/libpurple/protocols/jabber/pep.c b/libpurple/protocols/jabber/pep.c
--- a/libpurple/protocols/jabber/pep.c
+++ b/libpurple/protocols/jabber/pep.c
@@ -46,8 +46,7 @@ void jabber_pep_uninit(void) {
 	 * cleanup of removing the handler and feature are handled here and by
 	 * jabber_features_destroy() in jabber.c
 	 */
-	g_hash_table_destroy(pep_handlers);
-	pep_handlers = NULL;
+	g_clear_pointer(&pep_handlers, g_hash_table_destroy);
 }
 
 void
diff --git a/libpurple/protocols/jabber/presence.c b/libpurple/protocols/jabber/presence.c
--- a/libpurple/protocols/jabber/presence.c
+++ b/libpurple/protocols/jabber/presence.c
@@ -1244,6 +1244,5 @@ void jabber_presence_init(void)
 
 void jabber_presence_uninit(void)
 {
-	g_hash_table_destroy(presence_handlers);
-	presence_handlers = NULL;
+	g_clear_pointer(&presence_handlers , g_hash_table_destroy);
 }
diff --git a/libpurple/purplechatconversation.c b/libpurple/purplechatconversation.c
--- a/libpurple/purplechatconversation.c
+++ b/libpurple/purplechatconversation.c
@@ -261,8 +261,7 @@ purple_chat_conversation_finalize(GObjec
 
 	g_clear_pointer(&priv->users, g_hash_table_destroy);
 
-	g_list_free_full(priv->ignored, g_free);
-	priv->ignored = NULL;
+	g_clear_list(&priv->ignored, g_free);
 
 	g_clear_pointer(&priv->who, g_free);
 	g_clear_pointer(&priv->topic, g_free);
diff --git a/libpurple/purpletags.c b/libpurple/purpletags.c
--- a/libpurple/purpletags.c
+++ b/libpurple/purpletags.c
@@ -40,10 +40,7 @@ static void
 purple_tags_dispose(GObject *obj) {
 	PurpleTags *tags = PURPLE_TAGS(obj);
 
-	if(tags->tags != NULL) {
-		g_list_free_full(tags->tags, g_free);
-		tags->tags = NULL;
-	}
+	g_clear_list(&tags->tags, g_free);
 
 	G_OBJECT_CLASS(purple_tags_parent_class)->dispose(obj);
 }
diff --git a/libpurple/request-datasheet.c b/libpurple/request-datasheet.c
--- a/libpurple/request-datasheet.c
+++ b/libpurple/request-datasheet.c
@@ -109,8 +109,7 @@ purple_request_datasheet_free(PurpleRequ
 	g_list_free_full(sheet->record_list,
 		(GDestroyNotify)purple_request_datasheet_record_free);
 
-	if (sheet->marked_for_rem != NULL)
-		g_hash_table_destroy(sheet->marked_for_rem);
+	g_clear_pointer(&sheet->marked_for_rem, g_hash_table_destroy);
 
 	g_free(sheet);
 }
@@ -381,9 +380,8 @@ purple_request_datasheet_record_remove_a
 {
 	g_return_if_fail(sheet != NULL);
 
-	g_list_free_full(sheet->record_list,
-		(GDestroyNotify)purple_request_datasheet_record_free);
-	sheet->record_list = NULL;
+	g_clear_list(&sheet->record_list,
+	             (GDestroyNotify)purple_request_datasheet_record_free);
 	g_hash_table_remove_all(sheet->record_li_by_key);
 
 	purple_signal_emit(sheet, "record-changed", sheet, NULL);
@@ -394,8 +392,7 @@ purple_request_datasheet_record_mark_all
 {
 	const GList *it;
 
-	if (sheet->marked_for_rem != NULL)
-		g_hash_table_destroy(sheet->marked_for_rem);
+	g_clear_pointer(&sheet->marked_for_rem, g_hash_table_destroy);
 	sheet->marked_for_rem = g_hash_table_new(g_direct_hash, g_direct_equal);
 
 	it = purple_request_datasheet_get_records(sheet);
diff --git a/libpurple/request/purplerequestfieldlist.c b/libpurple/request/purplerequestfieldlist.c
--- a/libpurple/request/purplerequestfieldlist.c
+++ b/libpurple/request/purplerequestfieldlist.c
@@ -216,8 +216,7 @@ void
 purple_request_field_list_clear_selected(PurpleRequestFieldList *field) {
 	g_return_if_fail(PURPLE_IS_REQUEST_FIELD_LIST(field));
 
-	g_list_free_full(field->selected, g_free);
-	field->selected = NULL;
+	g_clear_list(&field->selected, g_free);
 
 	g_hash_table_remove_all(field->selected_table);
 	g_object_notify(G_OBJECT(field), "valid");
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -1268,11 +1268,9 @@ purple_savedstatuses_uninit(void)
 		sync_statuses();
 	}
 
-	g_list_free_full(saved_statuses, (GDestroyNotify)free_saved_status);
-	saved_statuses = NULL;
+	g_clear_list(&saved_statuses, (GDestroyNotify)free_saved_status);
 
-	g_hash_table_destroy(creation_times);
-	creation_times = NULL;
+	g_clear_pointer(&creation_times, g_hash_table_destroy);
 
 	g_signal_handlers_disconnect_by_func(manager,
 	                                     G_CALLBACK(purple_savedstatus_unset_all_substatuses),
diff --git a/libpurple/server.c b/libpurple/server.c
--- a/libpurple/server.c
+++ b/libpurple/server.c
@@ -457,8 +457,7 @@ struct chat_invite_data {
 
 static void chat_invite_data_free(struct chat_invite_data *cid)
 {
-	if (cid->components)
-		g_hash_table_destroy(cid->components);
+	g_clear_pointer(&cid->components, g_hash_table_destroy);
 	g_free(cid);
 }
 
diff --git a/libpurple/signals.c b/libpurple/signals.c
--- a/libpurple/signals.c
+++ b/libpurple/signals.c
@@ -475,8 +475,7 @@ purple_signals_uninit(void)
 {
 	g_return_if_fail(instance_table != NULL);
 
-	g_hash_table_destroy(instance_table);
-	instance_table = NULL;
+	g_clear_pointer(&instance_table, g_hash_table_destroy);
 }
 
 /**************************************************************************
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -541,8 +541,7 @@ void purple_got_protocol_handler_uri(con
 	purple_signal_emit_return_1(purple_get_core(), "uri-handler", proto, cmd, params);
 
 	g_free(cmd);
-	if (params)
-		g_hash_table_destroy(params);
+	g_clear_pointer(&params, g_hash_table_destroy);
 }
 
 const char *
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -322,8 +322,7 @@ rebuild_chat_entries(PidginChatData *dat
 		child = gtk_widget_get_first_child(GTK_WIDGET(data->rq_data.vbox));
 	}
 
-	g_list_free(data->entries);
-	data->entries = NULL;
+	g_clear_list(&data->entries, NULL);
 
 	if(!PURPLE_IS_PROTOCOL_CHAT(protocol)) {
 		return;
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -2290,6 +2290,5 @@ void
 pidgin_request_uninit(void)
 {
 	purple_signals_disconnect_by_handle(pidgin_request_get_handle());
-	g_hash_table_destroy(datasheet_stock);
-	datasheet_stock = NULL;
+	g_clear_pointer(&datasheet_stock, g_hash_table_destroy);
 }
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -657,8 +657,7 @@ gboolean pidgin_auto_parent_window(GtkWi
 			break;
 		}
 	}
-	if (windows)
-		g_list_free(windows);
+	g_clear_list(&windows, NULL);
 	if (parent) {
 		gtk_window_set_transient_for(GTK_WINDOW(widget), parent);
 		return TRUE;
diff --git a/pidgin/gtkxfer.c b/pidgin/gtkxfer.c
--- a/pidgin/gtkxfer.c
+++ b/pidgin/gtkxfer.c
@@ -944,8 +944,7 @@ pidgin_xfers_init(void)
 void
 pidgin_xfers_uninit(void)
 {
-	if (xfer_dialog != NULL)
-		pidgin_xfer_dialog_destroy(xfer_dialog);
+	g_clear_pointer(&xfer_dialog, pidgin_xfer_dialog_destroy);
 }
 
 void
diff --git a/pidgin/plugins/disco/xmppdisco.c b/pidgin/plugins/disco/xmppdisco.c
--- a/pidgin/plugins/disco/xmppdisco.c
+++ b/pidgin/plugins/disco/xmppdisco.c
@@ -711,8 +711,7 @@ static gboolean
 xmpp_disco_unload(GPluginPlugin *plugin, G_GNUC_UNUSED gboolean unload,
                   G_GNUC_UNUSED GError **error)
 {
-	g_hash_table_destroy(iq_callbacks);
-	iq_callbacks = NULL;
+	g_clear_pointer(&iq_callbacks, g_hash_table_destroy);
 
 	purple_signals_disconnect_by_handle(plugin);
 	pidgin_disco_dialogs_destroy_all();
diff --git a/pidgin/plugins/gestures/stroke-draw.c b/pidgin/plugins/gestures/stroke-draw.c
--- a/pidgin/plugins/gestures/stroke-draw.c
+++ b/pidgin/plugins/gestures/stroke-draw.c
@@ -319,9 +319,7 @@ gstroke_cleanup (GtkWidget *widget)
 	struct gstroke_metrics *metrics;
 	GHashTable *hash_table = (GHashTable *)g_object_steal_data(G_OBJECT(widget),
 	                                                           GSTROKE_SIGNALS);
-	if (hash_table) {
-		g_hash_table_destroy(hash_table);
-	}
+	g_clear_pointer(&hash_table, g_hash_table_destroy);
 
 	metrics = (struct gstroke_metrics *)g_object_steal_data(G_OBJECT(widget),
 	                                                        GSTROKE_METRICS);
diff --git a/pidgin/plugins/gestures/stroke.c b/pidgin/plugins/gestures/stroke.c
--- a/pidgin/plugins/gestures/stroke.c
+++ b/pidgin/plugins/gestures/stroke.c
@@ -22,13 +22,9 @@
 
 
 void
-_gstroke_init (struct gstroke_metrics *metrics)
-{
-	if (metrics->pointList != NULL) {
-		g_slist_free_full(metrics->pointList, g_free);
-		metrics->pointList = NULL;
-		metrics->point_count = 0;
-	}
+_gstroke_init(struct gstroke_metrics *metrics) {
+	g_clear_slist(&metrics->pointList, g_free);
+	metrics->point_count = 0;
 }
 
 /* figure out which bin the point falls in */
