/soc/2013/ankitkv/gobjectification: 63c14353a0f4: Manage refcoun...

Ankit Vani a at nevitus.org
Tue Oct 1 16:42:22 EDT 2013


Changeset: 63c14353a0f4402896ce138bb7fb1830c76df0c5
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-10-02 01:56 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/63c14353a0f4

Description:

Manage refcounts in some libpurple callbacks

diffstat:

 libpurple/account.c                 |  12 +++++++++---
 libpurple/protocols/gg/chat.c       |   5 ++++-
 libpurple/protocols/msn/msn.c       |  13 ++++++++++---
 libpurple/protocols/null/nullprpl.c |   6 ++++--
 4 files changed, 27 insertions(+), 9 deletions(-)

diffs (162 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -204,6 +204,8 @@ purple_account_register_completed_cb(gpo
 	if (priv->registration_cb)
 		(priv->registration_cb)(account, succeeded, priv->registration_cb_user_data);
 
+	g_object_unref(account);
+
 	return FALSE;
 }
 
@@ -211,7 +213,7 @@ void
 purple_account_register_completed(PurpleAccount *account, gboolean succeeded)
 {
 	gpointer *data = g_new0(gpointer, 2);
-	data[0] = account;
+	data[0] = g_object_ref(account);
 	data[1] = succeeded ? GINT_TO_POINTER(1) : NULL;
 
 	purple_timeout_add(0, (GSourceFunc)purple_account_register_completed_cb,
@@ -1020,6 +1022,8 @@ set_public_alias_unsupported(gpointer da
 
 	failure_cb(closure->account,
 	           _("This protocol does not support setting a public alias."));
+
+	g_object_unref(closure->account);
 	g_free(closure);
 
 	return FALSE;
@@ -1046,7 +1050,7 @@ purple_account_set_public_alias(PurpleAc
 	else if (failure_cb) {
 		struct public_alias_closure *closure =
 				g_new0(struct public_alias_closure, 1);
-		closure->account = account;
+		closure->account = g_object_ref(account);
 		closure->failure_cb = failure_cb;
 		purple_timeout_add(0, set_public_alias_unsupported, closure);
 	}
@@ -1060,6 +1064,8 @@ get_public_alias_unsupported(gpointer da
 
 	failure_cb(closure->account,
 	           _("This protocol does not support fetching the public alias."));
+
+	g_object_unref(account);
 	g_free(closure);
 
 	return FALSE;
@@ -1086,7 +1092,7 @@ purple_account_get_public_alias(PurpleAc
 	else if (failure_cb) {
 		struct public_alias_closure *closure =
 				g_new0(struct public_alias_closure, 1);
-		closure->account = account;
+		closure->account = g_object_ref(account);
 		closure->failure_cb = failure_cb;
 		purple_timeout_add(0, get_public_alias_unsupported, closure);
 	}
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
@@ -535,7 +535,9 @@ void ggp_chat_got_message(PurpleConnecti
 
 static gboolean ggp_chat_roomlist_get_list_finish(gpointer roomlist)
 {
-	purple_roomlist_set_in_progress((PurpleRoomlist*)roomlist, FALSE);
+	purple_roomlist_set_in_progress(PURPLE_ROOMLIST(roomlist), FALSE);
+	g_object_unref(roomlist);
+
 	return FALSE;
 }
 
@@ -601,6 +603,7 @@ PurpleRoomlist * ggp_chat_roomlist_get_l
 
 	//TODO
 	//purple_roomlist_set_in_progress(roomlist, FALSE);
+	g_object_ref(roomlist);
 	purple_timeout_add(1, ggp_chat_roomlist_get_list_finish, roomlist);
 	return roomlist;
 }
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -182,6 +182,8 @@ set_public_alias_length_error(gpointer d
 	PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb;
 
 	failure_cb(closure->account, _("Your new MSN friendly name is too long."));
+
+	g_object_unref(closure->account);
 	g_free(closure);
 
 	return FALSE;
@@ -254,7 +256,7 @@ msn_set_public_alias(PurpleConnection *p
 			if (failure_cb) {
 				struct public_alias_closure *closure =
 					g_new0(struct public_alias_closure, 1);
-				closure->account = account;
+				closure->account = g_object_ref(account);
 				closure->failure_cb = failure_cb;
 				purple_timeout_add(0, set_public_alias_length_error, closure);
 			} else {
@@ -296,6 +298,8 @@ get_public_alias_cb(gpointer data)
 	alias = purple_account_get_string(closure->account, "display-name",
 	                                  purple_account_get_username(closure->account));
 	success_cb(closure->account, alias);
+
+	g_object_unref(account);
 	g_free(closure);
 
 	return FALSE;
@@ -309,7 +313,7 @@ msn_get_public_alias(PurpleConnection *p
 	struct public_alias_closure *closure = g_new0(struct public_alias_closure, 1);
 	PurpleAccount *account = purple_connection_get_account(pc);
 
-	closure->account = account;
+	closure->account = g_object_ref(account);
 	closure->success_cb = success_cb;
 	purple_timeout_add(0, get_public_alias_cb, closure);
 }
@@ -1402,8 +1406,11 @@ msn_send_me_im(gpointer data)
 {
 	MsnIMData *imdata = data;
 	serv_got_im(imdata->gc, imdata->who, imdata->msg, imdata->flags, imdata->when);
+
+	g_object_unref(imdata->gc);
 	g_free(imdata->msg);
 	g_free(imdata);
+
 	return FALSE;
 }
 
@@ -1624,7 +1631,7 @@ msn_send_im(PurpleConnection *gc, const 
 		g_free(post);
 
 		serv_got_typing_stopped(gc, who);
-		imdata->gc = gc;
+		imdata->gc = g_object_ref(gc);
 		imdata->who = who;
 		imdata->msg = body_str;
 		imdata->flags = flags & ~PURPLE_MESSAGE_SEND;
diff --git a/libpurple/protocols/null/nullprpl.c b/libpurple/protocols/null/nullprpl.c
--- a/libpurple/protocols/null/nullprpl.c
+++ b/libpurple/protocols/null/nullprpl.c
@@ -978,7 +978,9 @@ static void nullprpl_set_chat_topic(Purp
 }
 
 static gboolean nullprpl_finish_get_roomlist(gpointer roomlist) {
-  purple_roomlist_set_in_progress((PurpleRoomlist *)roomlist, FALSE);
+  purple_roomlist_set_in_progress(PURPLE_ROOMLIST(roomlist), FALSE);
+  g_object_unref(roomlist);
+
   return FALSE;
 }
 
@@ -1027,7 +1029,7 @@ static PurpleRoomlist *nullprpl_roomlist
   }
 
   g_list_free(seen_ids);
-  purple_timeout_add(1 /* ms */, nullprpl_finish_get_roomlist, roomlist);
+  purple_timeout_add(1 /* ms */, nullprpl_finish_get_roomlist, g_object_ref(roomlist));
   return roomlist;
 }
 



More information about the Commits mailing list