/soc/2013/ankitkv/gobjectification: fbaa6f248ebc: Free the list ...
Ankit Vani
a at nevitus.org
Mon Sep 2 18:45:19 EDT 2013
Changeset: fbaa6f248ebcf5de2d350dba1ceaf1f230c2db66
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-03 04:15 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/fbaa6f248ebc
Description:
Free the list returned by purple_protocols_get_all()
diffstat:
finch/gntaccount.c | 2 ++
libpurple/example/nullclient.c | 8 +++++---
libpurple/plugins/one_time_password.c | 14 ++++++++++----
libpurple/protocols.h | 3 ++-
pidgin/gtkaccount.c | 4 +++-
pidgin/gtkutils.c | 17 ++++++++++-------
6 files changed, 32 insertions(+), 16 deletions(-)
diffs (178 lines):
diff --git a/finch/gntaccount.c b/finch/gntaccount.c
--- a/finch/gntaccount.c
+++ b/finch/gntaccount.c
@@ -655,6 +655,8 @@ edit_account_continue(PurpleAccount *acc
gnt_widget_show(window);
gnt_box_readjust(GNT_BOX(window));
gnt_widget_draw(window);
+
+ g_list_free(list);
}
static void
diff --git a/libpurple/example/nullclient.c b/libpurple/example/nullclient.c
--- a/libpurple/example/nullclient.c
+++ b/libpurple/example/nullclient.c
@@ -240,7 +240,7 @@ connect_to_signals_for_demonstration_pur
int main(int argc, char *argv[])
{
- GList *iter;
+ GList *list, *iter;
int i, num;
GList *names = NULL;
const char *protocol = NULL;
@@ -264,14 +264,16 @@ int main(int argc, char *argv[])
printf("libpurple initialized.\n");
- iter = purple_protocols_get_all();
- for (i = 0; iter; iter = iter->next) {
+ list = purple_protocols_get_all();
+ for (i = 0, iter = list; iter; iter = iter->next) {
PurpleProtocol *protocol = iter->data;
if (protocol && purple_protocol_get_name(protocol)) {
printf("\t%d: %s\n", i++, purple_protocol_get_name(protocol));
names = g_list_append(names, (gpointer)purple_protocol_get_id(protocol));
}
}
+ g_list_free(list);
+
printf("Select the protocol [0-%d]: ", i-1);
res = fgets(name, sizeof(name), stdin);
if (!res) {
diff --git a/libpurple/plugins/one_time_password.c b/libpurple/plugins/one_time_password.c
--- a/libpurple/plugins/one_time_password.c
+++ b/libpurple/plugins/one_time_password.c
@@ -57,10 +57,12 @@ plugin_load(PurplePlugin *plugin)
{
PurpleProtocol *protocol;
PurpleAccountOption *option;
- GList *l;
+ GList *list, *l;
+
+ list = purple_protocols_get_all();
/* Register protocol preference. */
- for (l = purple_protocols_get_all(); l != NULL; l = l->next) {
+ for (l = list; l != NULL; l = l->next) {
protocol = PURPLE_PROTOCOL(l->data);
if (protocol != NULL && !(purple_protocol_get_options(protocol) & OPT_PROTO_NO_PASSWORD)) {
option = purple_account_option_bool_new(_("One Time Password"),
@@ -68,6 +70,7 @@ plugin_load(PurplePlugin *plugin)
purple_protocol_get_protocol_options(protocol) = g_list_append(purple_protocol_get_protocol_options(protocol), option);
}
}
+ g_list_free(list);
/* Register callback. */
purple_signal_connect(purple_connections_get_handle(), "signed-on",
@@ -81,10 +84,12 @@ plugin_unload(PurplePlugin *plugin)
{
PurpleProtocol *protocol;
PurpleAccountOption *option;
- GList *l, *options;
+ GList *list, *l, *options;
+
+ list = purple_protocols_get_all();
/* Remove protocol preference. */
- for (l = purple_protocols_get_all(); l != NULL; l = l->next) {
+ for (l = list; l != NULL; l = l->next) {
protocol = PURPLE_PROTOCOL(l->data);
if (protocol != NULL && !(purple_protocol_get_options(protocol) & OPT_PROTO_NO_PASSWORD)) {
options = purple_protocol_get_protocol_options(protocol);
@@ -99,6 +104,7 @@ plugin_unload(PurplePlugin *plugin)
}
}
}
+ g_list_free(list);
/* Callback will be automagically unregistered */
diff --git a/libpurple/protocols.h b/libpurple/protocols.h
--- a/libpurple/protocols.h
+++ b/libpurple/protocols.h
@@ -591,7 +591,8 @@ gboolean purple_protocols_remove(PurpleP
/**
* Returns a list of all loaded protocols.
*
- * @constreturn A list of all loaded protocols.
+ * @return A list of all loaded protocols. The list is owned by the caller, and
+ * must be g_list_free()d to avoid leaking the nodes.
*/
GList *purple_protocols_get_all(void);
diff --git a/pidgin/gtkaccount.c b/pidgin/gtkaccount.c
--- a/pidgin/gtkaccount.c
+++ b/pidgin/gtkaccount.c
@@ -1735,8 +1735,10 @@ pidgin_account_dialog_show_continue(Purp
if (dialog->account == NULL) {
/* Select the first protocol in the list*/
GList *protocol_list = purple_protocols_get_all();
- if (protocol_list != NULL)
+ if (protocol_list != NULL) {
dialog->protocol_id = g_strdup(purple_protocol_get_id(PURPLE_PROTOCOL(protocol_list->data)));
+ g_list_free(protocol_list);
+ }
}
else
{
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -549,7 +549,7 @@ aop_option_menu_replace_menu(GtkWidget *
}
static GdkPixbuf *
-pidgin_create_protocol_icon_from_protocol(PurpleProtocol *protocol, PidginProtocolIconSize size, PurpleAccount *account)
+pidgin_create_icon_from_protocol(PurpleProtocol *protocol, PidginProtocolIconSize size, PurpleAccount *account)
{
const char *protoname = NULL;
char *tmp;
@@ -628,7 +628,7 @@ create_protocols_menu(const char *defaul
GdkPixbuf *pixbuf = NULL;
GtkTreeIter iter;
GtkListStore *ls;
- GList *p;
+ GList *list, *p;
int i;
ls = gtk_list_store_new(AOP_COLUMN_COUNT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
@@ -637,13 +637,15 @@ create_protocols_menu(const char *defaul
aop_menu->default_item = 0;
aop_menu->model = GTK_TREE_MODEL(ls);
- for (p = purple_protocols_get_all(), i = 0;
+ list = purple_protocols_get_all();
+
+ for (p = list, i = 0;
p != NULL;
p = p->next, i++) {
- protocol = (PurpleProtocol *)p->data;
-
- pixbuf = pidgin_create_protocol_icon_from_protocol(protocol, PIDGIN_PROTOCOL_ICON_SMALL, NULL);
+ protocol = PURPLE_PROTOCOL(p->data);
+
+ pixbuf = pidgin_create_icon_from_protocol(protocol, PIDGIN_PROTOCOL_ICON_SMALL, NULL);
gtk_list_store_append(ls, &iter);
gtk_list_store_set(ls, &iter,
@@ -658,6 +660,7 @@ create_protocols_menu(const char *defaul
if (default_proto_id != NULL && !strcmp(purple_protocol_get_id(protocol), default_proto_id))
aop_menu->default_item = i;
}
+ g_list_free(list);
return aop_menu;
}
@@ -1689,7 +1692,7 @@ pidgin_create_protocol_icon(PurpleAccoun
protocol = purple_protocols_find(purple_account_get_protocol_id(account));
if (protocol == NULL)
return NULL;
- return pidgin_create_protocol_icon_from_protocol(protocol, size, account);
+ return pidgin_create_icon_from_protocol(protocol, size, account);
}
static void
More information about the Commits
mailing list