# HG changeset patch
# Node ID eb20922244ce
# Parent  3fe515350d59
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -524,6 +524,7 @@
 		parse_setting((PurpleBlistNode*)buddy, x);
 	}
 
+	g_clear_object(&account);
 	g_free(name);
 	g_free(alias);
 }
@@ -603,6 +604,7 @@
 		parse_setting((PurpleBlistNode*)chat, x);
 	}
 
+	g_clear_object(&account);
 	g_free(alias);
 }
 
diff --git a/libpurple/protocols/demo/purpledemoprotocolactions.c b/libpurple/protocols/demo/purpledemoprotocolactions.c
--- a/libpurple/protocols/demo/purpledemoprotocolactions.c
+++ b/libpurple/protocols/demo/purpledemoprotocolactions.c
@@ -154,6 +154,8 @@
 	g_object_set_data(G_OBJECT(connection), "reaping-time",
 	                  GINT_TO_POINTER(DEFAULT_REAP_TIME));
 	g_timeout_add_seconds(1, cb, connection);
+
+	g_clear_object(&account);
 }
 
 static void
@@ -219,6 +221,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	/* Alternate through all four combinations of {masked, multiline}. */
 	masked = form % 2 == 1;
@@ -276,6 +279,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	purple_request_choice(connection, _("Request Choice Demo"),
 	                      _("Please pick an option…"), NULL, _("foo"),
@@ -314,6 +318,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	purple_request_action(connection, _("Request Action Demo"),
 	                      _("Please choose an action…"), NULL, 1,
@@ -372,6 +377,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	wait = g_new0(PurpleDemoProtocolWaitData, 1);
 
@@ -620,6 +626,8 @@
 	                      G_CALLBACK(purple_demo_protocol_request_fields_cancel_cb),
 	                      purple_request_cpar_from_connection(connection),
 	                      NULL);
+
+	g_clear_object(&account);
 }
 
 static void
@@ -656,6 +664,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	purple_request_file(connection, _("Request File Demo"),
 	                    "example.txt", FALSE,
@@ -685,6 +694,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	purple_request_folder(connection, _("Request Folder Demo"), NULL,
 	                      G_CALLBACK(purple_demo_protocol_request_path_ok_cb),
@@ -725,6 +735,8 @@
 	if(counter >= G_N_ELEMENTS(contacts)) {
 		counter = 0;
 	}
+
+	g_clear_object(&account);
 }
 
 /******************************************************************************
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -203,6 +203,8 @@
 	purple_request_file(action, _("Save buddylist..."), NULL, TRUE,
 		G_CALLBACK(ggp_callback_buddylist_save_ok), NULL,
 		purple_request_cpar_from_connection(connection), connection);
+
+	g_clear_object(&account);
 }
 
 static void
@@ -228,6 +230,8 @@
 	purple_request_file(action, _("Load buddylist from file..."), NULL,
 		FALSE, G_CALLBACK(ggp_callback_buddylist_load_ok), NULL,
 		purple_request_cpar_from_connection(connection), connection);
+
+	g_clear_object(&account);
 }
 
 /* ----- BLOCK BUDDIES -------------------------------------------------- */
@@ -673,6 +677,8 @@
 	im = purple_im_conversation_new(account, screenname);
 	purple_conversation_present(im);
 
+	g_clear_object(&account);
+
 	return TRUE;
 }
 
@@ -1009,6 +1015,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	ggp_multilogon_dialog(connection);
 }
@@ -1032,6 +1039,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	ggp_status_broadcasting_dialog(connection);
 }
@@ -1055,6 +1063,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	ggp_pubdir_search(connection, NULL);
 }
@@ -1078,6 +1087,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 
 	ggp_pubdir_set_info(connection);
 }
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
@@ -692,6 +692,8 @@
 	                      _("Cancel"), NULL,
 	                      purple_request_cpar_from_connection(connection),
 	                      connection);
+
+	g_clear_object(&account);
 }
 
 /*---------------------------------------*/
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
@@ -1669,6 +1669,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 	js = purple_connection_get_protocol_data(connection);
 
 	page = purple_request_page_new();
@@ -2839,18 +2840,23 @@
 
 			purple_conversation_present(im);
 
-			if (params != NULL) {
+			if(params != NULL) {
 				body = g_hash_table_lookup(params, "body");
 			}
 
-			if (body && *body)
+			if(body && *body) {
 				purple_conversation_send_confirm(im, body);
+			}
+
+			g_clear_object(&acct)
+
 			return TRUE;
 		}
 	} else if (g_hash_table_lookup_extended(params, "roster", NULL, NULL)) {
 		char *name = g_hash_table_lookup(params, "name");
 		if (user && *user) {
 			purple_blist_request_add_buddy(acct, user, NULL, name);
+			g_clear_object(&acct);
 			return TRUE;
 		}
 	} else if (g_hash_table_lookup_extended(params, "join", NULL, NULL)) {
@@ -2859,9 +2865,12 @@
 			GHashTable *params = jabber_chat_info_defaults(gc, user);
 			jabber_chat_join(gc, params);
 		}
+		g_clear_object(&acct);
 		return TRUE;
 	}
 
+	g_clear_object(&acct);
+
 	return FALSE;
 }
 
diff --git a/libpurple/protocols/jabber/usernick.c b/libpurple/protocols/jabber/usernick.c
--- a/libpurple/protocols/jabber/usernick.c
+++ b/libpurple/protocols/jabber/usernick.c
@@ -106,6 +106,7 @@
 	manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(manager, account_id);
 	connection = purple_account_get_connection(account);
+	g_clear_object(&account);
 	js = purple_connection_get_protocol_data(connection);
 
 	/* since the nickname might have been changed by another resource of this account, we always have to request the old one
diff --git a/libpurple/purpleaccountmanager.h b/libpurple/purpleaccountmanager.h
--- a/libpurple/purpleaccountmanager.h
+++ b/libpurple/purpleaccountmanager.h
@@ -154,7 +154,7 @@
  *
  * Looks up an account based on its id property.
  *
- * Returns: (transfer none): The account if found, otherwise %NULL.
+ * Returns: (transfer full): The account if found, otherwise %NULL.
  *
  * Since: 3.0.0
  */
@@ -169,7 +169,7 @@
  * Attempts to find an account in @manager with the matching @username and
  * @protocol_id.
  *
- * Returns: (transfer none): The account if found, otherwise %NULL.
+ * Returns: (transfer full): The account if found, otherwise %NULL.
  *
  * Since: 3.0.0
  */
@@ -184,7 +184,7 @@
  *
  * Attempts to find an account in @manager with a custom matching function.
  *
- * Returns: (transfer none): The account if found, otherwise %NULL.
+ * Returns: (transfer full): The account if found, otherwise %NULL.
  *
  * Since: 3.0.0
  */
diff --git a/libpurple/purpleaccountmanager.c b/libpurple/purpleaccountmanager.c
--- a/libpurple/purpleaccountmanager.c
+++ b/libpurple/purpleaccountmanager.c
@@ -516,7 +516,7 @@
 		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 
 		if(purple_strequal(purple_contact_info_get_id(info), id)) {
-			return account;
+			return g_object_ref(account);
 		}
 	}
 
@@ -553,7 +553,7 @@
 		if(purple_strequal(existing_normalized, normalized)) {
 			g_free(normalized);
 
-			return account;
+			return g_object_ref(account);
 		}
 		g_free(normalized);
 	}
@@ -573,7 +573,7 @@
 	if(g_ptr_array_find_with_equal_func(manager->accounts, data, func, &index)) {
 		PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
 
-		return account;
+		return g_object_ref(account);
 	}
 
 	return NULL;
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -412,6 +412,7 @@
 	}
 
 	if(ret->type == NULL) {
+		g_clear_object(&ret->account);
 		g_free(ret);
 		return NULL;
 	}
@@ -673,6 +674,7 @@
 		if (substatus->account == account)
 		{
 			saved_status->substatuses = g_list_delete_link(saved_status->substatuses, iter);
+			g_clear_object(&substatus->account);
 			g_free(substatus->message);
 			g_free(substatus);
 			return;
diff --git a/libpurple/tests/test_account_manager.c b/libpurple/tests/test_account_manager.c
--- a/libpurple/tests/test_account_manager.c
+++ b/libpurple/tests/test_account_manager.c
@@ -143,7 +143,8 @@
 	found = purple_account_manager_find_custom(manager,
 	                                           test_purple_account_manager_find_func,
 	                                           "test");
-	g_assert_nonnull(found);
+	g_assert_true(PURPLE_IS_ACCOUNT(found));
+	g_clear_object(&found);
 
 	/* Finally remove the account and verify it can't be found. */
 	purple_account_manager_remove(manager, account);
diff --git a/pidgin/pidginapplication.c b/pidgin/pidginapplication.c
--- a/pidgin/pidginapplication.c
+++ b/pidgin/pidginapplication.c
@@ -341,6 +341,7 @@
 	account = purple_account_manager_find_by_id(manager, id);
 	if(PURPLE_IS_ACCOUNT(account)) {
 		purple_account_connect(account);
+		g_clear_object(&account);
 	}
 }
 
@@ -372,6 +373,8 @@
 		if(purple_account_get_enabled(account)) {
 			purple_account_set_enabled(account, FALSE);
 		}
+
+		g_clear_object(&account);
 	}
 }
 
@@ -413,6 +416,8 @@
 
 		pidgin_application_present_transient_window(application,
 		                                            GTK_WINDOW(account_manager));
+
+		g_clear_object(&account);
 	}
 }
 
@@ -434,6 +439,8 @@
 		if(!purple_account_get_enabled(account)) {
 			purple_account_set_enabled(account, TRUE);
 		}
+
+		g_clear_object(&account);
 	}
 }
 
diff --git a/pidgin/plugins/unity/unity.c b/pidgin/plugins/unity/unity.c
--- a/pidgin/plugins/unity/unity.c
+++ b/pidgin/plugins/unity/unity.c
@@ -298,6 +298,8 @@
 		                                        account, cname);
 	}
 
+	g_clear_object(&account);
+
 	if (conv) {
 		GtkRoot *root = NULL;
 		GtkWidget *win = NULL;
