pidgin: 0ec1ab63: Check if memory has been freed by lookin...

markdoliner at pidgin.im markdoliner at pidgin.im
Thu Feb 4 20:20:47 EST 2010


-----------------------------------------------------------------
Revision: 0ec1ab6374bf7c1c3ef7f92ac8024287fae29f0e
Ancestor: 091e51ec52b6a8997b13d2bae08a177dcdc409d5
Author: markdoliner at pidgin.im
Date: 2010-02-05T01:18:18
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0ec1ab6374bf7c1c3ef7f92ac8024287fae29f0e

Modified files:
        libpurple/protocols/myspace/myspace.c
        libpurple/protocols/myspace/session.c
        libpurple/protocols/myspace/session.h
        libpurple/protocols/myspace/user.c

ChangeLog: 

Check if memory has been freed by looking at its contents does not work
100% of the time.  If any of these functions are called with an invalid
object, then the correct fix is to determine why the function was called
and prevent it from being called.

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/myspace.c	24dfb0496390d036c339df25aa402469a76051b3
+++ libpurple/protocols/myspace/myspace.c	5d634622111bd89b46f48173bf829421e4c659e4
@@ -251,7 +251,6 @@ msim_send_bm(MsimSession *session, const
 	MsimMessage *msg;
 	const gchar *from_username;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(who != NULL, FALSE);
 	g_return_val_if_fail(text != NULL, FALSE);
 
@@ -344,8 +343,6 @@ msim_new_reply_callback(MsimSession *ses
 {
 	guint rid;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
-
 	rid = session->next_rid++;
 
 	g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb);
@@ -394,8 +391,6 @@ msim_status_text(PurpleBuddy *buddy)
 	gc = purple_account_get_connection(account);
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
-
 	display_name = headline = NULL;
 
 	/* Retrieve display name and/or headline, depending on user preference. */
@@ -442,10 +437,8 @@ msim_tooltip_text(PurpleBuddy *buddy, Pu
 		MsimSession *session;
 		PurpleAccount *account = purple_buddy_get_account(buddy);
 		PurpleConnection *gc = purple_account_get_connection(account);
- 
-		session = (MsimSession *)gc->proto_data;
 
-		g_return_if_fail(MSIM_SESSION_VALID(session));
+		session = (MsimSession *)gc->proto_data;
 
 		/* TODO: if (full), do something different? */
 
@@ -694,7 +687,6 @@ msim_login_challenge(MsimSession *sessio
 	gsize nc_len;
 	gboolean ret;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE);
@@ -783,7 +775,6 @@ msim_is_username_set(MsimSession *sessio
 static gboolean
 msim_is_username_set(MsimSession *session, MsimMessage *msg)
 {
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 	g_return_val_if_fail(session->gc != NULL, FALSE);
 
@@ -842,8 +833,6 @@ msim_check_alive(gpointer data)
 
 	session = (MsimSession *)data;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
-
 	delta = time(NULL) - session->last_comm;
 
 	/* purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta); */
@@ -970,11 +959,6 @@ msim_check_inbox(gpointer data)
 
 	session = (MsimSession *)data;
 
-	if (!MSIM_SESSION_VALID(session)) {
-		purple_debug_info("msim", "msim_check_inbox: session invalid, stopping the mail check.\n");
-		return FALSE;
-	}
-
 	purple_debug_info("msim", "msim_check_inbox: checking mail\n");
 	g_return_val_if_fail(msim_send(session,
 			"persist", MSIM_TYPE_INTEGER, 1,
@@ -1215,8 +1199,6 @@ gboolean msim_we_are_logged_on(MsimSessi
 {
 	MsimMessage *body;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
-
 	/* Set display name to username (otherwise will show email address) */
 	purple_connection_set_display_name(session->gc, session->username);
 
@@ -1382,7 +1364,6 @@ msim_incoming_status(MsimSession *sessio
 	gchar *username;
 	gchar *unrecognized_msg;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	/* Helpfully looked up by msim_incoming_resolve() for us. */
@@ -1577,7 +1558,6 @@ msim_incoming_action_or_im(MsimSession *
 	gchar *msg_text, *username;
 	gboolean rc;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	msg_text = msim_msg_get_string(msg, "msg");
@@ -1797,7 +1777,6 @@ msim_process_reply(MsimSession *session,
 	gpointer data;
 	guint rid, cmd, dsn, lid;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	msim_store_user_info(session, msg, NULL);
@@ -1848,7 +1827,6 @@ msim_error(MsimSession *session, MsimMes
 	gchar *errmsg, *full_errmsg;
 	guint err;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	err = msim_msg_get_integer(msg, "err");
@@ -1962,7 +1940,6 @@ msim_incoming_resolved(MsimSession *sess
 	gchar *username;
 	MsimMessage *msg, *body;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
 	g_return_if_fail(userinfo != NULL);
 
 	body = msim_msg_get_dictionary(userinfo, "body");
@@ -1998,7 +1975,6 @@ msim_preprocess_incoming(MsimSession *se
 static gboolean
 msim_preprocess_incoming(MsimSession *session, MsimMessage *msg)
 {
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	if (msim_msg_get(msg, "bm") && msim_msg_get(msg, "f")) {
@@ -2071,7 +2047,6 @@ msim_input_cb(gpointer gc_uncasted, gint
 	}
 
 	g_return_if_fail(cond == PURPLE_INPUT_READ);
-	g_return_if_fail(MSIM_SESSION_VALID(session));
 
 	/* Mark down that we got data, so we don't timeout. */
 	session->last_comm = time(NULL);
@@ -2303,10 +2278,6 @@ msim_close(PurpleConnection *gc)
 
 	gc->proto_data = NULL;
 
-	if (!MSIM_SESSION_VALID(session)) {
-		return;
-	}
-
 	if (session->gc->inpa) {
 		purple_input_remove(session->gc->inpa);
 	}
@@ -2348,8 +2319,6 @@ msim_send_im(PurpleConnection *gc, const
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
-
 	message_msim = html_to_msim_markup(session, message);
 
 	if (msim_send_bm(session, who, message_msim, MSIM_BM_ACTION_OR_IM_DELAYABLE)) {
@@ -2390,8 +2359,6 @@ msim_send_typing(PurpleConnection *gc, c
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
-
 	switch (state) {
 		case PURPLE_TYPING:
 			typing_str = "%typing%";
@@ -2421,8 +2388,6 @@ msim_get_info_cb(MsimSession *session, c
 	PurpleNotifyUserInfo *user_info;
 	MsimUser *user;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	/* Get user{name,id} from msim_get_info, passed as an MsimMessage for
 	   orthogonality. */
 	msg = (MsimMessage *)data;
@@ -2480,8 +2445,6 @@ msim_get_info(PurpleConnection *gc, cons
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	/* Obtain uid of buddy. */
 	user = msim_find_user(session, username);
 
@@ -2515,7 +2478,6 @@ msim_set_status_code(MsimSession *sessio
 static void
 msim_set_status_code(MsimSession *session, guint status_code, gchar *statstring)
 {
-	g_return_if_fail(MSIM_SESSION_VALID(session));
 	g_return_if_fail(statstring != NULL);
 
 	purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n",
@@ -2548,8 +2510,6 @@ msim_set_status(PurpleAccount *account, 
 
 	session = (MsimSession *)account->gc->proto_data;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	type = purple_status_get_type(status);
 	pres = purple_status_get_presence(status);
 
@@ -2613,8 +2573,6 @@ msim_set_idle(PurpleConnection *gc, int 
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	status = purple_account_get_active_status(session->account);
 
 	if (time == 0) {
@@ -3005,8 +2963,6 @@ msim_send_really_raw(PurpleConnection *g
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
-
 	/* Loop until all data is sent, or a failure occurs. */
 	total_bytes_sent = 0;
 	do {
@@ -3041,7 +2997,6 @@ msim_send_raw(MsimSession *session, cons
 {
 	size_t len;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
============================================================
--- libpurple/protocols/myspace/session.c	e83604658f8e5ad67c316f667383e05f616df90d
+++ libpurple/protocols/myspace/session.c	229eeaf9acc466ab68c976a4fd0cdec87f46abee
@@ -76,8 +76,6 @@ msim_session_destroy(MsimSession *sessio
 void
 msim_session_destroy(MsimSession *session)
 {
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	session->magic = -1;
 
 	g_free(session->rxbuf);
============================================================
--- libpurple/protocols/myspace/session.h	3baae9e8d22cd26b2e14d04cbd30667fb8abf211
+++ libpurple/protocols/myspace/session.h	b6fd056e7c512e5210fac889456be2e2e7b84d3a
@@ -54,9 +54,6 @@ typedef struct _MsimSession
 	guint inbox_handle;                 /**< The handle for the mail check timer */
 } MsimSession;
 
-/* Check if an MsimSession is valid */
-#define MSIM_SESSION_VALID(s) (session != NULL && session->magic == MSIM_SESSION_STRUCT_MAGIC)
-
 MsimSession *msim_session_new(PurpleAccount *acct);
 void msim_session_destroy(MsimSession *session);
 
============================================================
--- libpurple/protocols/myspace/user.c	9d836002975a1ecf44250582ce330536bce0e070
+++ libpurple/protocols/myspace/user.c	2ae51913fb06835cb21cef0c53519e7e42026f82
@@ -414,7 +414,6 @@ msim_store_user_info(MsimSession *sessio
 	gchar *username;
 	MsimMessage *body, *body_node;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
 
 	body = msim_msg_get_dictionary(msg, "body");
@@ -566,7 +565,6 @@ msim_lookup_user(MsimSession *session, c
 	gchar *field_name;
 	guint rid, cmd, dsn, lid;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
 	g_return_if_fail(user != NULL);
 	/* Callback can be null to not call anything, just lookup & store information. */
 	/*g_return_if_fail(cb != NULL);*/
@@ -626,8 +624,6 @@ static void msim_username_is_set_cb(Msim
 
 	purple_debug_info("msim","username_is_set made\n");
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	cmd = msim_msg_get_integer(userinfo, "cmd");
 	dsn = msim_msg_get_integer(userinfo, "dsn");
 	uid = msim_msg_get_integer(userinfo, "uid");
@@ -707,7 +703,6 @@ msim_set_username(MsimSession *session, 
 	MsimMessage *body;
 	guint rid;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
 	g_return_if_fail(username != NULL);
 	g_return_if_fail(cb != NULL);
 
@@ -754,9 +749,6 @@ static void msim_set_username_confirmed_
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
-
 	user_msg = msim_msg_new(
 			"user", MSIM_TYPE_STRING, g_strdup(msim_username_to_set),
 			NULL);
@@ -783,7 +775,6 @@ static void msim_username_is_available_c
 	purple_debug_info("msim_username_is_available_cb", "Look up username callback made\n");
 
 	msg = (MsimMessage *)data;
-	g_return_if_fail(MSIM_SESSION_VALID(session));
 	g_return_if_fail(msg != NULL);
 
 	username = msim_msg_get_string(msg, "user");
@@ -851,8 +842,6 @@ static void msim_check_username_availabi
 
 	session = (MsimSession *)gc->proto_data;
 
-	g_return_if_fail(MSIM_SESSION_VALID(session));
-
 	purple_debug_info("msim_check_username_availability_cb", "Checking username: %s\n", username_to_check);
 
 	user_msg = msim_msg_new(


More information about the Commits mailing list