[telepathy-gabble/master] main-debug: catch the Disconnected signal so we can call wocky_deinit() before dying.

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 11 07:56:18 PDT 2009


By properly freeing Wocky's ressources, valgrind's log won't be flooded
by false positive leaks.
---
 tests/twisted/main-debug.c |   49 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/tests/twisted/main-debug.c b/tests/twisted/main-debug.c
index 95c8958..628a01b 100644
--- a/tests/twisted/main-debug.c
+++ b/tests/twisted/main-debug.c
@@ -17,26 +17,73 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <stdlib.h>
+
 #include "gabble.h"
 #include "connection.h"
 #include "jingle-factory.h"
 #include "jingle-session.h"
 
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <telepathy-glib/dbus.h>
+#include <wocky/wocky.h>
+
 #include <lib/gibber/gibber-resolver.h>
 
 #include "resolver-fake.h"
 
+static DBusHandlerResult
+dbus_filter_function (DBusConnection *connection,
+    DBusMessage *message,
+    void *user_data)
+{
+  if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
+      !tp_strdiff (dbus_message_get_path (message), DBUS_PATH_LOCAL))
+    {
+      wocky_deinit ();
+      exit (1);
+    }
+
+  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 int
 main (int argc,
       char **argv)
 {
+  TpDBusDaemon *bus_daemon = NULL;
+  GError *error = NULL;
+  DBusConnection *connection;
+  int ret = 1;
+
   gabble_init ();
 
+  bus_daemon = tp_dbus_daemon_dup (&error);
+  if (bus_daemon == NULL)
+    {
+      g_warning ("%s", error->message);
+      g_error_free (error);
+      error = NULL;
+      goto out;
+    }
+
+  /* It appears that dbus-glib registers a filter that wrongly returns
+   * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any
+   * effect, we need to install it as soon as possible */
+  connection = dbus_g_connection_get_connection (
+      ((TpProxy *) bus_daemon)->dbus_connection);
+  dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL);
+
+  dbus_connection_set_exit_on_disconnect (connection, FALSE);
   /* needed for test-disco-no-reply.py */
   gabble_connection_set_disco_reply_timeout (3);
 
   gibber_resolver_set_resolver (GABBLE_TYPE_RESOLVER_FAKE);
   gabble_jingle_factory_set_test_mode ();
 
-  return gabble_main (argc, argv);
+  ret = gabble_main (argc, argv);
+
+out:
+  return ret;
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list