summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2023-03-21 00:39:45 -0500
committerElliott Sales de Andrade <quantum.analyst@gmail.com>2023-03-21 00:39:45 -0500
commit1b4f76976e1a069831b98518588f587be79b122c (patch)
tree0558873858c1d4b3fb27069c4932d729e3a7f397
parentae674f38b973f59afa38f5fbcb8b4c069188e59f (diff)
downloadpidgin-1b4f76976e1a069831b98518588f587be79b122c.tar.gz
Use g_clear_* helpers where useful
That is: * when the variable is set to `NULL` right after freeing * when the variable is checked for non-`NULL` before freeing * when the variable is a global (because they should be set to `NULL`, even if we don't really claim that things can be re-init'd) Testing Done: Compiled, and ran tests in valgrind. Reviewed at https://reviews.imfreedom.org/r/2369/
-rw-r--r--finch/gntaccount.c12
-rw-r--r--finch/gntblist.c6
-rw-r--r--finch/gntconn.c2
-rw-r--r--finch/gntnotify.c7
-rw-r--r--finch/gntprefs.c3
-rw-r--r--finch/plugins/gnttinyurl/gnttinyurl.c3
-rw-r--r--finch/plugins/grouping/grouping.c3
-rw-r--r--libpurple/buddyicon.c4
-rw-r--r--libpurple/buddylist.c10
-rw-r--r--libpurple/cmds.c3
-rw-r--r--libpurple/image-store.c9
-rw-r--r--libpurple/mediamanager.c6
-rw-r--r--libpurple/plugins/idle/idle.c3
-rw-r--r--libpurple/prefs.c6
-rw-r--r--libpurple/protocols/facebook/facebook.c2
-rw-r--r--libpurple/protocols/gg/chat.c3
-rw-r--r--libpurple/protocols/gg/message-prpl.c3
-rw-r--r--libpurple/protocols/gg/roster.c18
-rw-r--r--libpurple/protocols/gg/servconn.c2
-rw-r--r--libpurple/protocols/irc/parse.c2
-rw-r--r--libpurple/protocols/jabber/adhoccommands.c6
-rw-r--r--libpurple/protocols/jabber/auth.c3
-rw-r--r--libpurple/protocols/jabber/bosh.c3
-rw-r--r--libpurple/protocols/jabber/buddy.c4
-rw-r--r--libpurple/protocols/jabber/caps.c3
-rw-r--r--libpurple/protocols/jabber/data.c7
-rw-r--r--libpurple/protocols/jabber/disco.c3
-rw-r--r--libpurple/protocols/jabber/ibb.c7
-rw-r--r--libpurple/protocols/jabber/iq.c5
-rw-r--r--libpurple/protocols/jabber/jabber.c23
-rw-r--r--libpurple/protocols/jabber/jingle/rtp.c3
-rw-r--r--libpurple/protocols/jabber/pep.c3
-rw-r--r--libpurple/protocols/jabber/presence.c3
-rw-r--r--libpurple/purplechatconversation.c3
-rw-r--r--libpurple/purpletags.c5
-rw-r--r--libpurple/request-datasheet.c11
-rw-r--r--libpurple/request/purplerequestfieldlist.c3
-rw-r--r--libpurple/savedstatuses.c6
-rw-r--r--libpurple/server.c3
-rw-r--r--libpurple/signals.c3
-rw-r--r--libpurple/util.c3
-rw-r--r--pidgin/gtkblist.c3
-rw-r--r--pidgin/gtkrequest.c3
-rw-r--r--pidgin/gtkutils.c3
-rw-r--r--pidgin/gtkxfer.c3
-rw-r--r--pidgin/plugins/disco/xmppdisco.c3
-rw-r--r--pidgin/plugins/gestures/stroke-draw.c4
-rw-r--r--pidgin/plugins/gestures/stroke.c10
48 files changed, 82 insertions, 164 deletions
diff --git a/finch/gntaccount.c b/finch/gntaccount.c
index 1baf2079f8..89134297b2 100644
--- a/finch/gntaccount.c
+++ b/finch/gntaccount.c
@@ -380,11 +380,7 @@ add_account_options(AccountEditDialog *dialog)
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
index 9af27689bb..d21e7846bb 100644
--- a/finch/gntblist.c
+++ b/finch/gntblist.c
@@ -1844,13 +1844,11 @@ reset_blist_window(G_GNUC_UNUSED GntWidget *window,
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
index 0f5e1535c0..a521ed646e 100644
--- 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
index 20e435eb83..797f9caf1a 100644
--- 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
index 5e90070d73..1525bb2fed 100644
--- 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
index be54530fb8..da5535c005 100644
--- a/finch/plugins/gnttinyurl/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl/gnttinyurl.c
@@ -552,8 +552,7 @@ tiny_url_unload(GPluginPlugin *plugin, G_GNUC_UNUSED gboolean shutdown,
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
index a09a4ed9a3..a7abacc43a 100644
--- 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
index 7070357199..ace0bc1e60 100644
--- 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
index 5e48f74487..81abd33acc 100644
--- 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
index 159176e61c..a0ea58aeca 100644
--- 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
index f92e53dbc2..4eeb596afb 100644
--- a/libpurple/image-store.c
+++ b/libpurple/image-store.c
@@ -219,13 +219,10 @@ _purple_image_store_init(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
index a4adb4184a..1b5613cc2e 100644
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -201,10 +201,8 @@ purple_media_manager_finalize (GObject *media)
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
index 1e5ee0894b..220f928303 100644
--- a/libpurple/plugins/idle/idle.c
+++ b/libpurple/plugins/idle/idle.c
@@ -256,8 +256,7 @@ purple_idle_unset_all_accounts_idle_time(G_GNUC_UNUSED GSimpleAction *action,
/* 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
index 84e72ecf1c..83e5d4d7c5 100644
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -923,8 +923,7 @@ purple_prefs_set_string_list(const char *name, GList *value)
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
index 48d342e664..04ed88e349 100644
--- 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
index 9768a9c969..c1729ae336 100644
--- a/libpurple/protocols/gg/chat.c
+++ b/libpurple/protocols/gg/chat.c
@@ -197,8 +197,7 @@ void ggp_chat_got_event(PurpleConnection *gc, const struct gg_event *ev)
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
index f42084be71..e74c5a31b7 100644
--- a/libpurple/protocols/gg/message-prpl.c
+++ b/libpurple/protocols/gg/message-prpl.c
@@ -590,8 +590,7 @@ ggp_message_format_to_gg(PurpleConversation *conv, const gchar *text)
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
index c688fb6cce..1072f3f121 100644
--- a/libpurple/protocols/gg/roster.c
+++ b/libpurple/protocols/gg/roster.c
@@ -148,16 +148,11 @@ static void ggp_roster_content_free(ggp_roster_content *content)
{
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(PurpleConnection *gc, uint32_t version)
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
index 79effa50f5..1088d51582 100644
--- a/libpurple/protocols/gg/servconn.c
+++ b/libpurple/protocols/gg/servconn.c
@@ -65,7 +65,7 @@ void ggp_servconn_setup(PurpleAccountOption *server_option)
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
index a16f10b003..12d0136dd8 100644
--- 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
index 22d0cb35b2..f06ddf80a9 100644
--- a/libpurple/protocols/jabber/adhoccommands.c
+++ b/libpurple/protocols/jabber/adhoccommands.c
@@ -73,8 +73,7 @@ jabber_adhoc_got_buddy_list(JabberStream *js, const char *from, PurpleXmlNode *q
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(JabberStream *js, G_GNUC_UNUSED const char *from,
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
index ddba00c8bc..f6d01911d6 100644
--- 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
index 5a3530abf9..6af10f05bc 100644
--- 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
index 03f521d816..d04f97cae1 100644
--- a/libpurple/protocols/jabber/buddy.c
+++ b/libpurple/protocols/jabber/buddy.c
@@ -1446,8 +1446,8 @@ jabber_time_parse(G_GNUC_UNUSED JabberStream *js, const char *from,
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
index 345d77a9cd..9bfc8f9c78 100644
--- 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
index f85b6b3d5c..d01db52762 100644
--- 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
index dbeffcb02d..c029b4472e 100644
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -462,8 +462,7 @@ jabber_disco_server_items_result_cb(JabberStream *js, const char *from,
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
index 63d58b9fc1..f91d69ee93 100644
--- 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
index c11e7e1029..1929fd681e 100644
--- 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
index 6c09a44271..cf43c270ed 100644
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -1025,12 +1025,9 @@ jabber_close(G_GNUC_UNUSED PurpleProtocol *protocol, PurpleConnection *gc) {
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 PurpleProtocol *protocol, PurpleConnection *gc) {
}
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 PurpleProtocolMedia *media,
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_clear_list(&jabber_features, (GDestroyNotify)jabber_feature_free);
+ g_clear_list(&jabber_identities, (GDestroyNotify)jabber_identity_free);
- g_hash_table_destroy(jabber_cmds);
- jabber_cmds = NULL;
+ 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
index 9bec4900d5..650d21ec49 100644
--- a/libpurple/protocols/jabber/jingle/rtp.c
+++ b/libpurple/protocols/jabber/jingle/rtp.c
@@ -821,8 +821,7 @@ jingle_rtp_get_media(JingleSession *session)
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
index 2e6c03be01..2a8b56f65d 100644
--- 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
index 02e62376ec..628ee5e7a9 100644
--- 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
index 0309b294e9..eed8a1ad63 100644
--- a/libpurple/purplechatconversation.c
+++ b/libpurple/purplechatconversation.c
@@ -261,8 +261,7 @@ purple_chat_conversation_finalize(GObject *obj) {
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
index 756640a20e..325c190e00 100644
--- 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
index a096153949..b69403b1d6 100644
--- a/libpurple/request-datasheet.c
+++ b/libpurple/request-datasheet.c
@@ -109,8 +109,7 @@ purple_request_datasheet_free(PurpleRequestDatasheet *sheet)
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_all(PurpleRequestDatasheet *sheet)
{
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_for_rem(PurpleRequestDatasheet *sheet)
{
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
index aee6039a35..d6db378d88 100644
--- 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
index f01e5d09f6..04c51b6a36 100644
--- 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
index 61fe6ed031..8395049a4c 100644
--- 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
index 9733b85485..8b87f0c587 100644
--- 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
index 51801c667d..5a5df99770 100644
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -541,8 +541,7 @@ void purple_got_protocol_handler_uri(const char *uri)
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
index ab4e96ebd8..6b60ee85e1 100644
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -322,8 +322,7 @@ rebuild_chat_entries(PidginChatData *data, const char *default_chat_name)
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
index eb6de41f58..7fabbfc9b1 100644
--- 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
index ab340f908c..de75a891b6 100644
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -657,8 +657,7 @@ gboolean pidgin_auto_parent_window(GtkWidget *widget)
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
index f7a9ad84c8..de9d7dae65 100644
--- 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
index 290a19cc0f..b918756672 100644
--- 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
index 2dc27a642f..6aff3ad02a 100644
--- 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
index 34ef020af3..aa29a04da4 100644
--- 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 */