/pidgin/main: e9b9320a985a: Drop PURPLE_CONNECTION_IS_VALID in f...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Tue May 20 06:46:13 EDT 2014
Changeset: e9b9320a985ac341c11227a0c265d2e7d361e108
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-05-20 12:46 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/e9b9320a985a
Description:
Drop PURPLE_CONNECTION_IS_VALID in favor of (temporary) PURPLE_ASSERT_CONNECTION_IS_VALID
diffstat:
libpurple/connection.c | 13 ++++++++
libpurple/connection.h | 18 ------------
libpurple/dbus-define-api.h | 2 -
libpurple/internal.h | 9 ++++++
libpurple/protocols/bonjour/jabber.c | 9 +++--
libpurple/protocols/gg/avatar.c | 13 ++------
libpurple/protocols/gg/edisc.c | 2 +-
libpurple/protocols/gg/gg.c | 2 +-
libpurple/protocols/gg/oauth/oauth-purple.c | 12 ++-----
libpurple/protocols/gg/pubdir-prpl.c | 12 ++++++--
libpurple/protocols/gg/roster.c | 2 +-
libpurple/protocols/gg/tcpsocket.c | 3 ++
libpurple/protocols/jabber/auth.c | 10 ++----
libpurple/protocols/jabber/auth_cyrus.c | 10 ++----
libpurple/protocols/jabber/jabber.c | 19 +++---------
libpurple/protocols/jabber/presence.c | 18 ++++++++----
libpurple/protocols/msn/userlist.c | 42 +++++++++++++++-------------
libpurple/protocols/mxit/actions.c | 10 +-----
libpurple/protocols/mxit/login.c | 5 +--
libpurple/protocols/silc/silc.c | 12 ++++----
libpurple/protocols/yahoo/libymsg.c | 2 +-
21 files changed, 108 insertions(+), 117 deletions(-)
diffs (truncated from 568 to 300 lines):
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -1037,6 +1037,19 @@ void
/**************************************************************************
* Connections API
**************************************************************************/
+
+void
+_purple_assert_connection_is_valid(PurpleConnection *gc,
+ const gchar *file, int line)
+{
+ if (gc && g_list_find(purple_connections_get_all(), gc))
+ return;
+
+ purple_debug_fatal("connection", "PURPLE_ASSERT_CONNECTION_IS_VALID(%p)"
+ " failed at %s:%d", gc, file, line);
+ exit(-1);
+}
+
void
purple_connections_disconnect_all(void)
{
diff --git a/libpurple/connection.h b/libpurple/connection.h
--- a/libpurple/connection.h
+++ b/libpurple/connection.h
@@ -566,24 +566,6 @@ GList *purple_connections_get_all(void);
*/
GList *purple_connections_get_connecting(void);
-/**
- * PURPLE_CONNECTION_IS_VALID:
- * @gc: The connection to check
- *
- * Checks if @gc is still a valid pointer to a connection.
- *
- * This is deprecated -- do not use this. Instead, cancel your asynchronous
- * request when the #PurpleConnection is destroyed.
- *
- * Returns: %TRUE if @gc is valid.
- */
-/*
- * TODO: Eventually this bad boy will be removed, because it is
- * a gross fix for a crashy problem.
- */
-#define PURPLE_CONNECTION_IS_VALID(gc) \
- (g_list_find(purple_connections_get_all(), (gc)) != NULL)
-
/**************************************************************************/
/* UI Registration Functions */
/**************************************************************************/
diff --git a/libpurple/dbus-define-api.h b/libpurple/dbus-define-api.h
--- a/libpurple/dbus-define-api.h
+++ b/libpurple/dbus-define-api.h
@@ -10,5 +10,3 @@ gboolean PURPLE_BUDDY_IS_ONLINE(PurpleBu
/* connection.h */
gboolean PURPLE_CONNECTION_IS_CONNECTED(PurpleConnection *connection);
-gboolean PURPLE_CONNECTION_IS_VALID(PurpleConnection *connection);
-
diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -149,6 +149,11 @@
[(condition) ? 1 : -1]; static_assertion_failed_ ## message dummy; \
(void)dummy; }
+/* This is meant to track use-after-free errors.
+ * TODO: it should be disabled in released code. */
+#define PURPLE_ASSERT_CONNECTION_IS_VALID(gc) \
+ _purple_assert_connection_is_valid(gc, __FILE__, __LINE__)
+
#ifdef __clang__
#define PURPLE_BEGIN_IGNORE_CAST_ALIGN \
@@ -390,4 +395,8 @@ void
void
_purple_socket_uninit(void);
+void
+_purple_assert_connection_is_valid(PurpleConnection *gc,
+ const gchar *file, int line);
+
#endif /* _PURPLE_INTERNAL_H_ */
diff --git a/libpurple/protocols/bonjour/jabber.c b/libpurple/protocols/bonjour/jabber.c
--- a/libpurple/protocols/bonjour/jabber.c
+++ b/libpurple/protocols/bonjour/jabber.c
@@ -1149,10 +1149,11 @@ bonjour_jabber_close_conversation(Bonjou
BonjourData *bd = NULL;
PurpleConnection *pc = purple_account_get_connection(bconv->account);
- if (PURPLE_CONNECTION_IS_VALID(pc)) {
- bd = purple_connection_get_protocol_data(pc);
- bd->jabber_data->pending_conversations = g_slist_remove(bd->jabber_data->pending_conversations, bconv);
- }
+
+ PURPLE_ASSERT_CONNECTION_IS_VALID(pc);
+
+ bd = purple_connection_get_protocol_data(pc);
+ bd->jabber_data->pending_conversations = g_slist_remove(bd->jabber_data->pending_conversations, bconv);
/* Cancel any file transfers that are waiting to begin */
/* There wont be any transfers if it hasn't been attached to a buddy */
diff --git a/libpurple/protocols/gg/avatar.c b/libpurple/protocols/gg/avatar.c
--- a/libpurple/protocols/gg/avatar.c
+++ b/libpurple/protocols/gg/avatar.c
@@ -126,7 +126,7 @@ static gboolean ggp_avatar_timer_cb(gpoi
PurpleConnection *gc = _gc;
ggp_avatar_session_data *avdata;
- g_return_val_if_fail(PURPLE_CONNECTION_IS_VALID(gc), FALSE);
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
avdata = ggp_avatar_get_avdata(gc);
if (avdata->current_update != NULL) {
@@ -265,10 +265,7 @@ static void ggp_avatar_buddy_update_rece
const gchar *got_data;
size_t got_len;
- if (!PURPLE_CONNECTION_IS_VALID(gc)) {
- g_free(pending_update);
- return;
- }
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
avdata = ggp_avatar_get_avdata(gc);
g_assert(pending_update == avdata->current_update);
@@ -321,8 +318,7 @@ void ggp_avatar_own_set(PurpleConnection
{
ggp_avatar_own_data *own_data;
- if (!PURPLE_CONNECTION_IS_VALID(gc) || !PURPLE_CONNECTION_IS_CONNECTED(gc))
- return;
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
purple_debug_info("gg", "ggp_avatar_own_set(%p, %p)", gc, img);
@@ -387,8 +383,7 @@ static void ggp_avatar_own_sent(PurpleHt
PurpleConnection *gc =
purple_http_conn_get_purple_connection(http_conn);
- if (!PURPLE_CONNECTION_IS_VALID(gc))
- return;
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
if (!purple_http_response_is_successful(response)) {
purple_debug_error("gg", "ggp_avatar_own_sent: "
diff --git a/libpurple/protocols/gg/edisc.c b/libpurple/protocols/gg/edisc.c
--- a/libpurple/protocols/gg/edisc.c
+++ b/libpurple/protocols/gg/edisc.c
@@ -128,7 +128,7 @@ ggp_edisc_get_sdata(PurpleConnection *gc
{
GGPInfo *accdata;
- g_return_val_if_fail(PURPLE_CONNECTION_IS_VALID(gc), NULL);
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
accdata = purple_connection_get_protocol_data(gc);
g_return_val_if_fail(accdata != NULL, NULL);
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
@@ -420,7 +420,7 @@ void ggp_async_login_handler(gpointer _g
GGPInfo *info;
struct gg_event *ev;
- g_return_if_fail(PURPLE_CONNECTION_IS_VALID(gc));
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
info = purple_connection_get_protocol_data(gc);
diff --git a/libpurple/protocols/gg/oauth/oauth-purple.c b/libpurple/protocols/gg/oauth/oauth-purple.c
--- a/libpurple/protocols/gg/oauth/oauth-purple.c
+++ b/libpurple/protocols/gg/oauth/oauth-purple.c
@@ -115,10 +115,8 @@ static void ggp_oauth_request_token_got(
gboolean succ = TRUE;
const gchar *xml_raw;
- if (!PURPLE_CONNECTION_IS_VALID(data->gc)) {
- ggp_oauth_data_free(data);
- return;
- }
+ PURPLE_ASSERT_CONNECTION_IS_VALID(data->gc);
+
account = purple_connection_get_account(data->gc);
if (!purple_http_response_is_successful(response)) {
@@ -181,10 +179,8 @@ static void ggp_oauth_authorization_done
const char *url = "http://api.gadu-gadu.pl/access_token";
int response_code;
- if (!PURPLE_CONNECTION_IS_VALID(data->gc)) {
- ggp_oauth_data_free(data);
- return;
- }
+ PURPLE_ASSERT_CONNECTION_IS_VALID(data->gc);
+
account = purple_connection_get_account(data->gc);
response_code = purple_http_response_get_code(response);
diff --git a/libpurple/protocols/gg/pubdir-prpl.c b/libpurple/protocols/gg/pubdir-prpl.c
--- a/libpurple/protocols/gg/pubdir-prpl.c
+++ b/libpurple/protocols/gg/pubdir-prpl.c
@@ -199,7 +199,9 @@ static void ggp_pubdir_get_info_got_toke
PurpleHttpRequest *req;
ggp_pubdir_request *request = _request;
- if (!token || !PURPLE_CONNECTION_IS_VALID(gc)) {
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
+
+ if (!token) {
request->cb(gc, -1, NULL, 0, request->user_data);
ggp_pubdir_request_free(request);
return;
@@ -627,7 +629,9 @@ static void ggp_pubdir_search_got_token(
ggp_pubdir_request *request = _request;
gchar *query;
- if (!token || !PURPLE_CONNECTION_IS_VALID(gc)) {
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
+
+ if (!token) {
request->cb(gc, -1, NULL, 0, request->user_data);
ggp_pubdir_request_free(request);
return;
@@ -899,7 +903,9 @@ static void ggp_pubdir_set_info_got_toke
gchar *name, *surname, *city;
uin_t uin = record->uin;
- if (!token || !PURPLE_CONNECTION_IS_VALID(gc)) {
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
+
+ if (!token) {
/* TODO: notify about failure */
ggp_pubdir_record_free(record, 1);
return;
diff --git a/libpurple/protocols/gg/roster.c b/libpurple/protocols/gg/roster.c
--- a/libpurple/protocols/gg/roster.c
+++ b/libpurple/protocols/gg/roster.c
@@ -188,7 +188,7 @@ static gboolean ggp_roster_timer_cb(gpoi
{
PurpleConnection *gc = _gc;
- g_return_val_if_fail(PURPLE_CONNECTION_IS_VALID(gc), FALSE);
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
ggp_roster_send_update(gc);
diff --git a/libpurple/protocols/gg/tcpsocket.c b/libpurple/protocols/gg/tcpsocket.c
--- a/libpurple/protocols/gg/tcpsocket.c
+++ b/libpurple/protocols/gg/tcpsocket.c
@@ -41,6 +41,8 @@ ggp_tcpsocket_connected(PurpleSocket *ps
GGPInfo *info = purple_connection_get_protocol_data(gc);
int fd = -1;
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
+
if (error == NULL)
fd = purple_socket_get_fd(ps);
@@ -65,6 +67,7 @@ ggp_tcpsocket_connect(void *_gc, const c
PurpleConnection *gc = _gc;
PurpleSocket *ps;
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
g_return_val_if_fail(!purple_connection_is_disconnecting(gc), NULL);
g_return_val_if_fail(host != NULL, NULL);
diff --git a/libpurple/protocols/jabber/auth.c b/libpurple/protocols/jabber/auth.c
--- a/libpurple/protocols/jabber/auth.c
+++ b/libpurple/protocols/jabber/auth.c
@@ -93,9 +93,8 @@ auth_old_pass_cb(PurpleConnection *gc, P
const char *entry;
gboolean remember;
- /* The password prompt dialog doesn't get disposed if the account disconnects */
- if (!PURPLE_CONNECTION_IS_VALID(gc))
- return;
+ /* TODO: the password prompt dialog doesn't get disposed if the account disconnects */
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
account = purple_connection_get_account(gc);
js = purple_connection_get_protocol_data(gc);
@@ -123,9 +122,8 @@ auth_old_pass_cb(PurpleConnection *gc, P
static void
auth_no_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields)
{
- /* The password prompt dialog doesn't get disposed if the account disconnects */
- if (!PURPLE_CONNECTION_IS_VALID(gc))
- return;
+ /* TODO: the password prompt dialog doesn't get disposed if the account disconnects */
+ PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
/* Disable the account as the user has cancelled connecting */
purple_account_set_enabled(purple_connection_get_account(gc), purple_core_get_ui(), FALSE);
diff --git a/libpurple/protocols/jabber/auth_cyrus.c b/libpurple/protocols/jabber/auth_cyrus.c
--- a/libpurple/protocols/jabber/auth_cyrus.c
+++ b/libpurple/protocols/jabber/auth_cyrus.c
@@ -133,9 +133,8 @@ static void auth_pass_cb(PurpleConnectio
const char *entry;
More information about the Commits
mailing list