pidgin/pidgin

Parents 11764e84328d
Children 9fc7c3c226d8
Add new and free functions for structs to reduce duplication
--- a/libpurple/media/codec.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/media/codec.c Sun Nov 03 20:37:07 2019 +0300
@@ -69,13 +69,7 @@
purple_media_codec_get_instance_private(
PURPLE_MEDIA_CODEC(info));
g_free(priv->encoding_name);
- for (; priv->optional_params; priv->optional_params =
- g_list_delete_link(priv->optional_params, priv->optional_params)) {
- PurpleKeyValuePair *param = priv->optional_params->data;
- g_free(param->key);
- g_free(param->value);
- g_free(param);
- }
+ g_list_free_full(priv->optional_params, (GDestroyNotify)purple_key_value_pair_free);
G_OBJECT_CLASS(purple_media_codec_parent_class)->finalize(info);
}
--- a/libpurple/protocols/bonjour/mdns_common.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/bonjour/mdns_common.c Sun Nov 03 20:37:07 2019 +0300
@@ -137,24 +137,13 @@
return ret;
}
-static void free_presence_txt_records(GSList *lst) {
- PurpleKeyValuePair *kvp;
- while(lst) {
- kvp = lst->data;
- g_free(kvp->key);
- g_free(kvp->value);
- g_free(kvp);
- lst = g_slist_delete_link(lst, lst);
- }
-}
-
static gboolean publish_presence(BonjourDnsSd *data, PublishType type) {
GSList *txt_records;
gboolean ret;
txt_records = generate_presence_txt_records(data);
ret = _mdns_publish(data, type, txt_records);
- free_presence_txt_records(txt_records);
+ g_slist_free_full(txt_records, (GDestroyNotify)purple_key_value_pair_free);
return ret;
}
--- a/libpurple/protocols/jabber/adhoccommands.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/adhoccommands.c Sun Nov 03 20:37:07 2019 +0300
@@ -58,17 +58,9 @@
if(!jbr)
return;
- if(jbr->commands) {
- /* since the list we just received is complete, wipe the old one */
- while(jbr->commands) {
- JabberAdHocCommands *cmd = jbr->commands->data;
- g_free(cmd->jid);
- g_free(cmd->node);
- g_free(cmd->name);
- g_free(cmd);
- jbr->commands = g_list_delete_link(jbr->commands, jbr->commands);
- }
- }
+ /* 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;
for(item = query->child; item; item = item->next) {
JabberAdHocCommands *cmd;
@@ -241,14 +233,8 @@
return;
/* clean current list (just in case there is one) */
- while(js->commands) {
- JabberAdHocCommands *cmd = js->commands->data;
- g_free(cmd->jid);
- g_free(cmd->node);
- g_free(cmd->name);
- g_free(cmd);
- js->commands = g_list_delete_link(js->commands, js->commands);
- }
+ g_list_free_full(js->commands, (GDestroyNotify)jabber_adhoc_commands_free);
+ js->commands = NULL;
/* re-fill list */
for(item = query->child; item; item = item->next) {
--- a/libpurple/protocols/jabber/buddy.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/buddy.c Sun Nov 03 20:37:07 2019 +0300
@@ -58,6 +58,14 @@
gchar *last_message;
} JabberBuddyInfo;
+void jabber_adhoc_commands_free(JabberAdHocCommands *cmd)
+{
+ g_free(cmd->jid);
+ g_free(cmd->node);
+ g_free(cmd->name);
+ g_free(cmd);
+}
+
static void
jabber_buddy_resource_free(JabberBuddyResource *jbr)
{
@@ -65,15 +73,7 @@
jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr);
- while(jbr->commands) {
- JabberAdHocCommands *cmd = jbr->commands->data;
- g_free(cmd->jid);
- g_free(cmd->node);
- g_free(cmd->name);
- g_free(cmd);
- jbr->commands = g_list_delete_link(jbr->commands, jbr->commands);
- }
-
+ g_list_free_full(jbr->commands, (GDestroyNotify)jabber_adhoc_commands_free);
g_list_free_full(jbr->caps.exts, g_free);
g_free(jbr->name);
g_free(jbr->status);
--- a/libpurple/protocols/jabber/buddy.h Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/buddy.h Sun Nov 03 20:37:07 2019 +0300
@@ -93,6 +93,8 @@
gboolean commands_fetched;
} JabberBuddyResource;
+void jabber_adhoc_commands_free(JabberAdHocCommands *cmd);
+
void jabber_buddy_free(JabberBuddy *jb);
JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name,
gboolean create);
--- a/libpurple/protocols/jabber/caps.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/caps.c Sun Nov 03 20:37:07 2019 +0300
@@ -100,15 +100,7 @@
if (info == NULL)
return;
- while(info->identities) {
- JabberIdentity *id = info->identities->data;
- g_free(id->category);
- g_free(id->type);
- g_free(id->name);
- g_free(id->lang);
- g_free(id);
- info->identities = g_list_delete_link(info->identities, info->identities);
- }
+ g_list_free_full(info->identities, (GDestroyNotify)jabber_identity_free);
free_string_glist(info->features);
@@ -266,12 +258,7 @@
if (!category || !type)
continue;
- id = g_new0(JabberIdentity, 1);
- id->category = g_strdup(category);
- id->type = g_strdup(type);
- id->name = g_strdup(name);
- id->lang = g_strdup(lang);
-
+ id = jabber_identity_new(category, type, lang, name);
value->identities = g_list_append(value->identities,id);
} else if (purple_strequal(child->name, "x")) {
/* TODO: See #7814 -- this might cause problems if anyone
@@ -753,12 +740,7 @@
if (!category || !type)
continue;
- id = g_new0(JabberIdentity, 1);
- id->category = g_strdup(category);
- id->type = g_strdup(type);
- id->name = g_strdup(name);
- id->lang = g_strdup(lang);
-
+ id = jabber_identity_new(category, type, lang, name);
info->identities = g_list_append(info->identities, id);
} else if (purple_strequal(child->name, "feature")) {
/* parse feature */
--- a/libpurple/protocols/jabber/disco.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/disco.c Sun Nov 03 20:37:07 2019 +0300
@@ -91,10 +91,7 @@
/* TODO: When we support zeroconf proxies, fix this to handle them */
if (!(sh->jid && sh->host && sh->port > 0)) {
js->bs_proxies = g_list_remove(js->bs_proxies, sh);
- g_free(sh->jid);
- g_free(sh->host);
- g_free(sh->zeroconf);
- g_free(sh);
+ jabber_bytestreams_streamhost_free(sh);
}
}
--- a/libpurple/protocols/jabber/jabber.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/jabber.c Sun Nov 03 20:37:07 2019 +0300
@@ -1676,14 +1676,7 @@
g_list_free_full(js->chat_servers, g_free);
g_list_free_full(js->user_directories, g_free);
- while(js->bs_proxies) {
- JabberBytestreamsStreamhost *sh = js->bs_proxies->data;
- g_free(sh->jid);
- g_free(sh->host);
- g_free(sh->zeroconf);
- g_free(sh);
- js->bs_proxies = g_list_delete_link(js->bs_proxies, js->bs_proxies);
- }
+ g_list_free_full(js->bs_proxies, (GDestroyNotify)jabber_bytestreams_streamhost_free);
if (js->http_conns) {
soup_session_abort(js->http_conns);
@@ -1714,14 +1707,7 @@
g_free(js->sasl_password);
#endif
g_free(js->serverFQDN);
- while(js->commands) {
- JabberAdHocCommands *cmd = js->commands->data;
- g_free(cmd->jid);
- g_free(cmd->node);
- g_free(cmd->name);
- g_free(cmd);
- js->commands = g_list_delete_link(js->commands, js->commands);
- }
+ g_list_free_full(js->commands, (GDestroyNotify)jabber_adhoc_commands_free);
g_free(js->server_name);
g_free(js->certificate_CN);
g_free(js->gmail_last_time);
@@ -2018,29 +2004,23 @@
jabber_features = g_list_append(jabber_features, feat);
}
+static void jabber_feature_free(JabberFeature *feature) {
+ g_free(feature->namespace);
+ g_free(feature);
+}
+
void jabber_remove_feature(const char *namespace) {
GList *feature;
for(feature = jabber_features; feature; feature = feature->next) {
JabberFeature *feat = (JabberFeature*)feature->data;
if(purple_strequal(feat->namespace, namespace)) {
- g_free(feat->namespace);
- g_free(feature->data);
+ jabber_feature_free(feat);
jabber_features = g_list_delete_link(jabber_features, feature);
break;
}
}
}
-static void jabber_features_destroy(void)
-{
- while (jabber_features) {
- JabberFeature *feature = jabber_features->data;
- g_free(feature->namespace);
- g_free(feature);
- jabber_features = g_list_delete_link(jabber_features, jabber_features);
- }
-}
-
gint
jabber_identity_compare(gconstpointer a, gconstpointer b)
{
@@ -2065,6 +2045,26 @@
return g_strcmp0(ac->lang, bc->lang);
}
+JabberIdentity *jabber_identity_new(const gchar *category, const gchar *type,
+ const gchar *lang, const gchar *name)
+{
+ JabberIdentity *id = g_new0(JabberIdentity, 1);
+ id->category = g_strdup(category);
+ id->type = g_strdup(type);
+ id->lang = g_strdup(lang);
+ id->name = g_strdup(name);
+ return id;
+}
+
+void jabber_identity_free(JabberIdentity *id)
+{
+ g_free(id->category);
+ g_free(id->type);
+ g_free(id->lang);
+ g_free(id->name);
+ g_free(id);
+}
+
void jabber_add_identity(const gchar *category, const gchar *type,
const gchar *lang, const gchar *name)
{
@@ -2075,35 +2075,28 @@
g_return_if_fail(category != NULL);
g_return_if_fail(type != NULL);
+ ident = jabber_identity_new(category, type, lang, name);
+
/* Check if this identity is already there... */
- for (identity = jabber_identities; identity; identity = identity->next) {
- JabberIdentity *id = identity->data;
- if (purple_strequal(id->category, category) &&
- purple_strequal(id->type, type) &&
- purple_strequal(id->lang, lang))
- return;
+ identity = g_list_find_custom(jabber_identities, ident, jabber_identity_compare);
+ if (identity != NULL) {
+ jabber_identity_free(ident);
+ return;
}
- ident = g_new0(JabberIdentity, 1);
- ident->category = g_strdup(category);
- ident->type = g_strdup(type);
- ident->lang = g_strdup(lang);
- ident->name = g_strdup(name);
jabber_identities = g_list_insert_sorted(jabber_identities, ident,
jabber_identity_compare);
}
-static void jabber_identities_destroy(void)
+void jabber_bytestreams_streamhost_free(JabberBytestreamsStreamhost *sh)
{
- while (jabber_identities) {
- JabberIdentity *id = jabber_identities->data;
- g_free(id->category);
- g_free(id->type);
- g_free(id->lang);
- g_free(id->name);
- g_free(id);
- jabber_identities = g_list_delete_link(jabber_identities, jabber_identities);
- }
+ if(!sh)
+ return;
+
+ g_free(sh->jid);
+ g_free(sh->host);
+ g_free(sh->zeroconf);
+ g_free(sh);
}
gboolean jabber_stream_is_ssl(JabberStream *js)
@@ -3989,8 +3982,8 @@
#endif
jabber_auth_uninit();
- jabber_features_destroy();
- jabber_identities_destroy();
+ 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;
--- a/libpurple/protocols/jabber/jabber.h Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/jabber.h Sun Nov 03 20:37:07 2019 +0300
@@ -377,11 +377,16 @@
*/
void jabber_add_identity(const gchar *category, const gchar *type, const gchar *lang, const gchar *name);
+JabberIdentity *jabber_identity_new(const gchar *category, const gchar *type, const gchar *lang, const gchar *name);
+void jabber_identity_free(JabberIdentity *id);
+
/**
* GCompareFunc for JabberIdentity structs.
*/
gint jabber_identity_compare(gconstpointer a, gconstpointer b);
+void jabber_bytestreams_streamhost_free(JabberBytestreamsStreamhost *sh);
+
/**
* Returns true if this connection is over a secure (SSL) stream. Use this
* instead of checking js->gsc because BOSH stores its PurpleSslConnection
--- a/libpurple/protocols/jabber/si.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/protocols/jabber/si.c Sun Nov 03 20:37:07 2019 +0300
@@ -100,19 +100,6 @@
return NULL;
}
-static void
-jabber_si_free_streamhost(gpointer data) {
- JabberBytestreamsStreamhost *sh = data;
-
- if(!data)
- return;
-
- g_free(sh->jid);
- g_free(sh->host);
- g_free(sh->zeroconf);
- g_free(sh);
-}
-
static void jabber_si_bytestreams_attempt_connect(PurpleXfer *xfer);
@@ -140,7 +127,7 @@
streamhost->jid, streamhost->host,
error_message ? error_message : "(null)");
jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost);
- jabber_si_free_streamhost(streamhost);
+ jabber_bytestreams_streamhost_free(streamhost);
jabber_si_bytestreams_attempt_connect(xfer);
return;
}
@@ -328,7 +315,7 @@
if (jsx->connect_data == NULL)
{
jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost);
- jabber_si_free_streamhost(streamhost);
+ jabber_bytestreams_streamhost_free(streamhost);
jabber_si_bytestreams_attempt_connect(xfer);
}
}
@@ -815,7 +802,7 @@
}
jsx->streamhosts = g_list_remove_link(jsx->streamhosts, matched);
- g_list_free_full(jsx->streamhosts, jabber_si_free_streamhost);
+ g_list_free_full(jsx->streamhosts, (GDestroyNotify)jabber_bytestreams_streamhost_free);
jsx->streamhosts = matched;
@@ -1779,9 +1766,7 @@
g_source_remove(jsx->ibb_timeout_handle);
}
- if (jsx->streamhosts) {
- g_list_free_full(jsx->streamhosts, jabber_si_free_streamhost);
- }
+ g_list_free_full(jsx->streamhosts, (GDestroyNotify)jabber_bytestreams_streamhost_free);
if (jsx->ibb_session) {
purple_debug_info("jabber",
--- a/libpurple/purpleaccountoption.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/purpleaccountoption.c Sun Nov 03 20:37:07 2019 +0300
@@ -170,16 +170,6 @@
return option;
}
-static void
-purple_account_option_list_free(gpointer data, gpointer user_data)
-{
- PurpleKeyValuePair *kvp = data;
-
- g_free(kvp->value);
- g_free(kvp->key);
- g_free(kvp);
-}
-
void
purple_account_option_destroy(PurpleAccountOption *option)
{
@@ -196,7 +186,7 @@
else if (option->type == PURPLE_PREF_STRING_LIST)
{
g_list_free_full(option->default_value.list,
- (GDestroyNotify)purple_account_option_list_free);
+ (GDestroyNotify)purple_key_value_pair_free);
}
g_free(option);
@@ -258,7 +248,7 @@
g_return_if_fail(option->type == PURPLE_PREF_STRING_LIST);
g_list_free_full(option->default_value.list,
- (GDestroyNotify)purple_account_option_list_free);
+ (GDestroyNotify)purple_key_value_pair_free);
option->default_value.list = values;
}
--- a/libpurple/util.c Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/util.c Sun Nov 03 20:37:07 2019 +0300
@@ -4252,6 +4252,13 @@
return g_string_free(string, FALSE);
}
+void purple_key_value_pair_free(PurpleKeyValuePair *kvp)
+{
+ g_free(kvp->value);
+ g_free(kvp->key);
+ g_free(kvp);
+}
+
const gchar *
purple_get_host_name(void)
{
--- a/libpurple/util.h Sun Nov 03 20:33:05 2019 +0300
+++ b/libpurple/util.h Sun Nov 03 20:37:07 2019 +0300
@@ -88,6 +88,14 @@
char * purple_util_format_song_info(const char *title, const char *artist,
const char *album, gpointer unused);
+/**
+ * purple_key_value_pair_free:
+ * @kvp: The PurpleKeyValuePair to free.
+ *
+ * Frees a PurpleKeyValuePair.
+ */
+void purple_key_value_pair_free(PurpleKeyValuePair *kvp);
+
/**************************************************************************/
/* Utility Subsystem */
/**************************************************************************/
--- a/pidgin/gtkaccount.c Sun Nov 03 20:33:05 2019 +0300
+++ b/pidgin/gtkaccount.c Sun Nov 03 20:37:07 2019 +0300
@@ -773,6 +773,13 @@
}
static void
+protocol_opt_entry_free(ProtocolOptEntry *opt_entry)
+{
+ g_free(opt_entry->setting);
+ g_free(opt_entry);
+}
+
+static void
add_account_options(AccountPrefsDialog *dialog)
{
PurpleAccountOption *option;
@@ -797,12 +804,7 @@
dialog->protocol_frame = NULL;
}
- while (dialog->protocol_opt_entries != NULL) {
- ProtocolOptEntry *opt_entry = dialog->protocol_opt_entries->data;
- g_free(opt_entry->setting);
- g_free(opt_entry);
- dialog->protocol_opt_entries = g_list_delete_link(dialog->protocol_opt_entries, dialog->protocol_opt_entries);
- }
+ g_list_free_full(dialog->protocol_opt_entries, (GDestroyNotify)protocol_opt_entry_free);
if (dialog->protocol == NULL ||
purple_protocol_get_account_options(dialog->protocol) == NULL)
@@ -1246,12 +1248,7 @@
gtk_widget_destroy(dialog->window);
g_list_free(dialog->user_split_entries);
- while (dialog->protocol_opt_entries != NULL) {
- ProtocolOptEntry *opt_entry = dialog->protocol_opt_entries->data;
- g_free(opt_entry->setting);
- g_free(opt_entry);
- dialog->protocol_opt_entries = g_list_delete_link(dialog->protocol_opt_entries, dialog->protocol_opt_entries);
- }
+ g_list_free_full(dialog->protocol_opt_entries, (GDestroyNotify)protocol_opt_entry_free);
g_free(dialog->protocol_id);
g_object_unref(dialog->sg);
--- a/pidgin/gtkblist.c Sun Nov 03 20:33:05 2019 +0300
+++ b/pidgin/gtkblist.c Sun Nov 03 20:37:07 2019 +0300
@@ -3061,29 +3061,24 @@
}
static void
-pidgin_blist_destroy_tooltip_data(void)
-{
- while(gtkblist->tooltipdata) {
- struct tooltip_data *td = gtkblist->tooltipdata->data;
-
- if(td->avatar)
- g_object_unref(td->avatar);
- if(td->status_icon)
- g_object_unref(td->status_icon);
- if(td->protocol_icon)
- g_object_unref(td->protocol_icon);
- if (td->layout)
- g_object_unref(td->layout);
- if (td->name_layout)
- g_object_unref(td->name_layout);
- g_free(td);
- gtkblist->tooltipdata = g_list_delete_link(gtkblist->tooltipdata, gtkblist->tooltipdata);
- }
+tooltip_data_free(struct tooltip_data *td)
+{
+ if(td->avatar)
+ g_object_unref(td->avatar);
+ if(td->status_icon)
+ g_object_unref(td->status_icon);
+ if(td->protocol_icon)
+ g_object_unref(td->protocol_icon);
+ if (td->layout)
+ g_object_unref(td->layout);
+ if (td->name_layout)
+ g_object_unref(td->name_layout);
+ g_free(td);
}
void pidgin_blist_tooltip_destroy()
{
- pidgin_blist_destroy_tooltip_data();
+ g_list_free_full(gtkblist->tooltipdata, (GDestroyNotify)tooltip_data_free);
pidgin_tooltip_destroy();
}
@@ -3115,7 +3110,7 @@
if (gtkblist->tooltipdata) {
gtkblist->tipwindow = NULL;
- pidgin_blist_destroy_tooltip_data();
+ g_list_free_full(gtkblist->tooltipdata, (GDestroyNotify)tooltip_data_free);
}
gtkblist->tipwindow = widget;
@@ -3304,7 +3299,7 @@
if (gtkblist->tooltipdata) {
gtkblist->tipwindow = NULL;
- pidgin_blist_destroy_tooltip_data();
+ g_list_free_full(gtkblist->tooltipdata, (GDestroyNotify)tooltip_data_free);
}
gtk_tree_model_get_iter(GTK_TREE_MODEL(gtkblist->treemodel), &iter, path);
--- a/pidgin/plugins/ticker/ticker.c Sun Nov 03 20:33:05 2019 +0300
+++ b/pidgin/plugins/ticker/ticker.c Sun Nov 03 20:37:07 2019 +0300
@@ -188,12 +188,16 @@
td->timeout = g_timeout_add(11000, buddy_ticker_set_pixmap_cb, td);
}
+static void ticker_data_free(TickerData *td) {
+ if (td->timeout != 0)
+ g_source_remove(td->timeout);
+ g_free(td);
+}
+
static void buddy_ticker_remove(TickerData *td) {
gtk_ticker_remove(GTK_TICKER(ticker), td->ebox);
tickerbuds = g_list_remove(tickerbuds, td);
- if (td->timeout != 0)
- g_source_remove(td->timeout);
- g_free(td);
+ ticker_data_free(td);
}
static void buddy_ticker_update_contact(PurpleContact *contact) {
@@ -287,20 +291,14 @@
static void
signoff_cb(PurpleConnection *gc)
{
- TickerData *td;
if (!purple_connections_get_all()) {
- while (tickerbuds) {
- td = tickerbuds->data;
- tickerbuds = g_list_delete_link(tickerbuds, tickerbuds);
- if (td->timeout != 0)
- g_source_remove(td->timeout);
- g_free(td);
- }
+ g_list_free_full(tickerbuds, (GDestroyNotify)ticker_data_free);
gtk_widget_destroy(tickerwindow);
tickerwindow = NULL;
ticker = NULL;
} else {
GList *t = tickerbuds;
+ TickerData *td;
while (t) {
td = t->data;
t = t->next;
@@ -361,15 +359,7 @@
static gboolean
plugin_unload(PurplePlugin *plugin, GError **error)
{
- TickerData *td;
-
- while (tickerbuds) {
- td = tickerbuds->data;
- tickerbuds = g_list_delete_link(tickerbuds, tickerbuds);
- if (td->timeout != 0)
- g_source_remove(td->timeout);
- g_free(td);
- }
+ g_list_free_full(tickerbuds, (GDestroyNotify)ticker_data_free);
if (tickerwindow != NULL) {
gtk_widget_destroy(tickerwindow);