summaryrefslogtreecommitdiffstats
path: root/bus/connection.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/connection.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/connection.c')
-rw-r--r--bus/connection.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/bus/connection.c b/bus/connection.c
index a8616683..1b59819f 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -37,6 +37,7 @@ struct BusConnections
};
static int connection_data_slot = -1;
+static int connection_data_slot_refcount = 0;
typedef struct
{
@@ -51,6 +52,39 @@ typedef struct
#define BUS_CONNECTION_DATA(connection) (dbus_connection_get_data ((connection), connection_data_slot))
+static dbus_bool_t
+connection_data_slot_ref (void)
+{
+ if (connection_data_slot < 0)
+ {
+ connection_data_slot = dbus_connection_allocate_data_slot ();
+
+ if (connection_data_slot < 0)
+ return FALSE;
+
+ _dbus_assert (connection_data_slot_refcount == 0);
+ }
+
+ connection_data_slot_refcount += 1;
+
+ return TRUE;
+
+}
+
+static void
+connection_data_slot_unref (void)
+{
+ _dbus_assert (connection_data_slot_refcount > 0);
+
+ connection_data_slot_refcount -= 1;
+
+ if (connection_data_slot_refcount == 0)
+ {
+ dbus_connection_free_data_slot (connection_data_slot);
+ connection_data_slot = -1;
+ }
+}
+
void
bus_connection_disconnected (DBusConnection *connection)
{
@@ -209,6 +243,7 @@ free_connection_data (void *data)
if (d->oom_preallocated)
dbus_connection_free_preallocated_send (d->connection, d->oom_preallocated);
+
if (d->oom_message)
dbus_message_unref (d->oom_message);
@@ -222,17 +257,15 @@ bus_connections_new (BusContext *context)
{
BusConnections *connections;
- if (connection_data_slot < 0)
- {
- connection_data_slot = dbus_connection_allocate_data_slot ();
-
- if (connection_data_slot < 0)
- return NULL;
- }
+ if (!connection_data_slot_ref ())
+ return NULL;
connections = dbus_new0 (BusConnections, 1);
if (connections == NULL)
- return NULL;
+ {
+ connection_data_slot_unref ();
+ return NULL;
+ }
connections->refcount = 1;
connections->context = context;
@@ -268,7 +301,9 @@ bus_connections_unref (BusConnections *connections)
_dbus_list_clear (&connections->list);
- dbus_free (connections);
+ dbus_free (connections);
+
+ connection_data_slot_unref ();
}
}
@@ -286,6 +321,8 @@ bus_connections_setup_connection (BusConnections *connections,
d->connections = connections;
d->connection = connection;
+
+ _dbus_assert (connection_data_slot >= 0);
if (!dbus_connection_set_data (connection,
connection_data_slot,
@@ -329,6 +366,11 @@ bus_connections_setup_connection (BusConnections *connections,
out:
if (!retval)
{
+ if (!dbus_connection_set_data (connection,
+ connection_data_slot,
+ NULL, NULL))
+ _dbus_assert_not_reached ("failed to set connection data to null");
+
if (!dbus_connection_set_watch_functions (connection,
NULL, NULL, NULL,
connection,