summaryrefslogtreecommitdiffstats
path: root/bus/test.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-17 05:39:10 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-17 05:39:10 +0000
commitf7c24715b5489b28b47499eb252b941b735fa1bc (patch)
tree53e62e764a0c5e0ba25791b6f6ae3dbbf1fc4f54 /bus/test.c
parent15f02e1071ab14a7bc937cb61a4439a69c14f1a5 (diff)
2003-03-17 Havoc Pennington <hp@pobox.com>
All tests pass, no memleaks, no valgrind complaints. * bus/test.c: refcount handler_slot * bus/connection.c (bus_connections_new): refcount connection_data_slot * dbus/dbus-auth-script.c (_dbus_auth_script_run): delete unused bytes so that auth scripts pass. * bus/dispatch.c: init message_handler_slot so it gets allocated properly * bus/dispatch.c (message_handler_slot_ref): fix memleak * dbus/dbus-server-debug-pipe.c (_dbus_server_debug_pipe_new): dealloc server_pipe_hash when no longer used for benefit of leak checking * dbus/dbus-auth.c (process_command): memleak fix * bus/dispatch.c (check_hello_message): memleak fix
Diffstat (limited to 'bus/test.c')
-rw-r--r--bus/test.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/bus/test.c b/bus/test.c
index 7de1d811..bc195ef1 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -112,6 +112,49 @@ client_disconnect_handler (DBusMessageHandler *handler,
}
static int handler_slot = -1;
+static int handler_slot_refcount = 0;
+
+static dbus_bool_t
+handler_slot_ref (void)
+{
+ if (handler_slot < 0)
+ {
+ handler_slot = dbus_connection_allocate_data_slot ();
+
+ if (handler_slot < 0)
+ return FALSE;
+
+ _dbus_assert (handler_slot_refcount == 0);
+ }
+
+ handler_slot_refcount += 1;
+
+ return TRUE;
+
+}
+
+static void
+handler_slot_unref (void)
+{
+ _dbus_assert (handler_slot_refcount > 0);
+
+ handler_slot_refcount -= 1;
+
+ if (handler_slot_refcount == 0)
+ {
+ dbus_connection_free_data_slot (handler_slot);
+ handler_slot = -1;
+ }
+}
+
+static void
+free_handler (void *data)
+{
+ DBusMessageHandler *handler = data;
+
+ dbus_message_handler_unref (handler);
+ handler_slot_unref ();
+}
dbus_bool_t
bus_setup_debug_client (DBusConnection *connection)
@@ -119,11 +162,6 @@ bus_setup_debug_client (DBusConnection *connection)
DBusMessageHandler *disconnect_handler;
const char *to_handle[] = { DBUS_MESSAGE_LOCAL_DISCONNECT };
dbus_bool_t retval;
-
- if (handler_slot < 0)
- handler_slot = dbus_connection_allocate_data_slot ();
- if (handler_slot < 0)
- return FALSE;
disconnect_handler = dbus_message_handler_new (client_disconnect_handler,
NULL, NULL);
@@ -160,12 +198,17 @@ bus_setup_debug_client (DBusConnection *connection)
if (!_dbus_list_append (&clients, connection))
goto out;
- /* Set up handler to be destroyed */
+ if (!handler_slot_ref ())
+ goto out;
+
+ /* Set up handler to be destroyed */
if (!dbus_connection_set_data (connection, handler_slot,
disconnect_handler,
- (DBusFreeFunction)
- dbus_message_handler_unref))
- goto out;
+ free_handler))
+ {
+ handler_slot_unref ();
+ goto out;
+ }
retval = TRUE;