soc.2009.telepathy: 787e2f80: Improved memory handling, fixes crash an...

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Tue Jun 9 18:20:34 EDT 2009


-----------------------------------------------------------------
Revision: 787e2f80f0a2a2fbcc89b9cbd84ecb84d3705ce3
Ancestor: d7f6997170b369f26d85d77404f630093a20086f
Author: sttwister at soc.pidgin.im
Date: 2009-06-09T21:51:58
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/787e2f80f0a2a2fbcc89b9cbd84ecb84d3705ce3

Modified files:
        libpurple/protocols/telepathy/telepathy.c

ChangeLog: 

Improved memory handling, fixes crash and memory leak

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy.c	d2da985336316a46487ba31b058354eb56b8eae5
+++ libpurple/protocols/telepathy/telepathy.c	b18d5455e32bec54eb7e9c09ad488fc20cae45a2
@@ -848,27 +848,30 @@ status_changed_cb (TpConnection *proxy,
 			break;
 		}
 
-		if (reason != NULL && data->gc)
-			purple_connection_error_reason(data->gc, error, reason);
+		if (data)
+		{
+			if (reason != NULL && data->gc)
+				purple_connection_error_reason(data->gc, error, reason);
 
-		if (data->connection)
-		{
-			g_object_unref(data->connection);
-			data->connection = NULL;
-		}
+			if (data->connection != NULL)
+			{
+				g_object_unref(data->connection);
+				data->connection = NULL;
+			}
 
-		if (data->text_Channels != NULL)
-		{
-			g_hash_table_destroy(data->text_Channels);
-			data->text_Channels = NULL;
-		}
-		if (data->contacts != NULL)
-		{
-			g_hash_table_destroy(data->contacts);
-			data->contacts = NULL;
-		}
+			if (data->text_Channels != NULL)
+			{
+				g_hash_table_destroy(data->text_Channels);
+				data->text_Channels = NULL;
+			}
+			if (data->contacts != NULL)
+			{
+				g_hash_table_destroy(data->contacts);
+				data->contacts = NULL;
+			}
 
-		g_free(data);
+			g_free(data);
+		}
 
 	}
 	else if (arg_Status == TP_CONNECTION_STATUS_CONNECTING)
@@ -937,6 +940,10 @@ request_connection_cb (TpConnectionManag
 		{
 			purple_debug_error("telepathy", "Error creating TpConnection object: %s\n", error->message);
 			g_error_free(error);
+
+			g_object_unref(connection_data->connection);
+			connection_data->connection = NULL;
+			g_free(connection_data);
 			return;
 		}
 
@@ -1027,6 +1034,8 @@ telepathy_login(PurpleAccount *acct)
 
 	/* call RequestConnection with the specified parameters */
 	tp_cli_connection_manager_call_request_connection(data->cm, -1, data->protocol->name, options, request_connection_cb, gc, NULL, NULL);
+
+	g_hash_table_destroy(options);
 }
 
 static void
@@ -1036,26 +1045,17 @@ telepathy_close(PurpleConnection *gc)
 
 	purple_debug_info("telepathy", "We're closing, sorry :(\n");
 
-	/* make sure the connection is closed in dbus-land, 
-	 * or else we won't be able to recreate the connection */
-	if (data->connection)
+	if (data)
 	{
-		tp_cli_connection_call_disconnect(data->connection, -1, NULL, NULL, NULL, NULL);
-		g_object_unref(data->connection);
-		data->connection = NULL;
-		data->gc = NULL;
-	}
+		/* make sure the connection is closed in dbus-land, 
+		 * or else we won't be able to recreate the connection */
+		if (data->connection)
+		{
+			/* this will call status_changed_cb which will free everything */
+			tp_cli_connection_call_disconnect(data->connection, -1, NULL, NULL, NULL, NULL);
+		}
 
-	if (data->text_Channels != NULL)
-	{
-		g_hash_table_destroy(data->text_Channels);
-		data->text_Channels = NULL;
 	}
-	if (data->contacts != NULL)
-	{
-		g_hash_table_destroy(data->contacts);
-		data->contacts = NULL;
-	}
 }
 
 static void


More information about the Commits mailing list