pidgin: 3295ae2b: Allow setting a destroy-function for the...

sadrul at pidgin.im sadrul at pidgin.im
Fri Oct 9 20:56:39 EDT 2009


-----------------------------------------------------------------
Revision: 3295ae2bdb4e5cae80dc9a5cdd9c53e307d5a255
Ancestor: 784f5b030e397c41ef6ae9cb48de8ba61c871961
Author: sadrul at pidgin.im
Date: 2009-10-09T18:01:51
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3295ae2bdb4e5cae80dc9a5cdd9c53e307d5a255

Modified files:
        libpurple/protocols/msn/notification.c
        libpurple/protocols/msn/transaction.c
        libpurple/protocols/msn/transaction.h

ChangeLog: 

Allow setting a destroy-function for the data. Fixes a leak.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/notification.c	57687ea2d593d48aea92ac2135f98bc4aac78c6e
+++ libpurple/protocols/msn/notification.c	4a4a6a4a6ec6b733796a53b033e2ab40d3c6c689
@@ -582,7 +582,8 @@ msn_notification_send_fqy(MsnSession *se
 
 	trans = msn_transaction_new(cmdproc, "FQY", "%d", payload_len);
 	msn_transaction_set_payload(trans, payload, payload_len);
-	msn_transaction_set_data(trans, data);	/* XXX: 'data' leaks */
+	msn_transaction_set_data(trans, data);
+	msn_transaction_set_data_free(trans, g_free);
 	msn_cmdproc_send_trans(cmdproc, trans);
 }
 
@@ -962,9 +963,8 @@ fqy_cmd_post(MsnCmdProc *cmdproc, MsnCom
 			if (cmd->trans->data) {
 				MsnFqyCbData *fqy_data = cmd->trans->data;
 				fqy_data->cb(session, passport, network, fqy_data->data);
-				/* TODO: This leaks, but the server responds to FQY multiple times, so we
-				         can't free it yet. We need to figure out somewhere else to do so.
-				g_free(fqy_data); */
+				/* Don't free fqy_data yet since the server responds to FQY multipe times.
+				   It will be freed when cmd->trans is freed. */
 			}
 
 			g_free(passport);
============================================================
--- libpurple/protocols/msn/transaction.c	011f4dae0a78356902ee5e65d3c94964ac9a7cc0
+++ libpurple/protocols/msn/transaction.c	ca020d0b8f923338a86e8bef54fd2591b5cc15dd
@@ -59,6 +59,9 @@ msn_transaction_destroy(MsnTransaction *
 	g_free(trans->params);
 	g_free(trans->payload);
 
+	if (trans->data_free)
+		trans->data_free(trans->data);
+
 #if 0
 	if (trans->pendent_cmd != NULL)
 		msn_message_unref(trans->pendent_msg);
@@ -165,6 +168,12 @@ msn_transaction_set_data(MsnTransaction 
 	trans->data = data;
 }
 
+void msn_transaction_set_data_free(MsnTransaction *trans, GDestroyNotify fn)
+{
+	g_return_if_fail(trans != NULL);
+	trans->data_free = fn;
+}
+
 void
 msn_transaction_add_cb(MsnTransaction *trans, char *answer,
 					   MsnTransCb cb)
============================================================
--- libpurple/protocols/msn/transaction.h	cf301f1b8a0296102b9d509bdd3fd925eabd1aaa
+++ libpurple/protocols/msn/transaction.h	623b8d18405ad7e9169b7c290679d40489ecc502
@@ -48,6 +48,8 @@ struct _MsnTransaction
 	guint timer;
 
 	void *data; /**< The data to be used on the different callbacks. */
+	GDestroyNotify data_free;  /**< The function to free 'data', or @c NULL */
+
 	GHashTable *callbacks;
 	gboolean has_custom_callbacks;
 	MsnErrorCb error_cb;
@@ -71,6 +73,7 @@ void msn_transaction_set_data(MsnTransac
 void msn_transaction_set_payload(MsnTransaction *trans,
 								 const char *payload, int payload_len);
 void msn_transaction_set_data(MsnTransaction *trans, void *data);
+void msn_transaction_set_data_free(MsnTransaction *trans, GDestroyNotify fn);
 void msn_transaction_add_cb(MsnTransaction *trans, char *answer,
 							MsnTransCb cb);
 void msn_transaction_set_error_cb(MsnTransaction *trans, MsnErrorCb cb);


More information about the Commits mailing list