summaryrefslogtreecommitdiffstats
path: root/dbus
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 /dbus
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 'dbus')
-rw-r--r--dbus/dbus-auth-script.c1
-rw-r--r--dbus/dbus-auth.c1
-rw-r--r--dbus/dbus-connection.c6
-rw-r--r--dbus/dbus-dataslot.c11
-rw-r--r--dbus/dbus-server-debug-pipe.c60
5 files changed, 67 insertions, 12 deletions
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c
index d954c8dd..3aaf5688 100644
--- a/dbus/dbus-auth-script.c
+++ b/dbus/dbus-auth-script.c
@@ -541,6 +541,7 @@ _dbus_auth_script_run (const DBusString *filename)
if (_dbus_string_equal (&expected, unused))
{
+ _dbus_auth_delete_unused_bytes (auth);
_dbus_string_free (&expected);
}
else
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c
index 9e2b1d95..8f8aec44 100644
--- a/dbus/dbus-auth.c
+++ b/dbus/dbus-auth.c
@@ -1665,6 +1665,7 @@ process_command (DBusAuth *auth)
if (!_dbus_string_init (&args, _DBUS_INT_MAX))
{
+ _dbus_string_free (&command);
auth->needed_memory = TRUE;
return FALSE;
}
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index ed677e74..d70ff716 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -866,6 +866,8 @@ _dbus_connection_last_unref (DBusConnection *connection)
DBusHashIter iter;
DBusList *link;
+ _dbus_verbose ("Finalizing connection %p\n", connection);
+
_dbus_assert (connection->refcount == 0);
/* You have to disconnect the connection before unref:ing it. Otherwise
@@ -969,6 +971,10 @@ dbus_connection_unref (DBusConnection *connection)
connection->refcount -= 1;
last_unref = (connection->refcount == 0);
+#if 0
+ _dbus_verbose ("unref() connection %p count = %d\n", connection, connection->refcount);
+#endif
+
dbus_mutex_unlock (connection->mutex);
if (last_unref)
diff --git a/dbus/dbus-dataslot.c b/dbus/dbus-dataslot.c
index 53fb9e4c..46e2bfc1 100644
--- a/dbus/dbus-dataslot.c
+++ b/dbus/dbus-dataslot.c
@@ -57,6 +57,10 @@ _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator)
* Allocates an integer ID to be used for storing data
* in a #DBusDataSlotList.
*
+ * @todo all over the code we have foo_slot and foo_slot_refcount,
+ * would be better to add an interface for that to
+ * DBusDataSlotAllocator so it isn't cut-and-pasted everywhere.
+ *
* @param allocator the allocator
* @returns the integer ID, or -1 on failure
*/
@@ -103,6 +107,9 @@ _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator)
_dbus_assert (slot >= 0);
_dbus_assert (slot < allocator->n_allocated_slots);
+
+ _dbus_verbose ("Allocated slot %d on allocator %p total %d slots allocated %d used\n",
+ slot, allocator, allocator->n_allocated_slots, allocator->n_used_slots);
out:
dbus_mutex_unlock (allocator->lock);
@@ -137,6 +144,9 @@ _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
allocator->allocated_slots = NULL;
allocator->n_allocated_slots = 0;
}
+
+ _dbus_verbose ("Freed slot %d on allocator %p total %d allocated %d used\n",
+ slot, allocator, allocator->n_allocated_slots, allocator->n_used_slots);
dbus_mutex_unlock (allocator->lock);
}
@@ -243,6 +253,7 @@ _dbus_data_slot_list_get (DBusDataSlotAllocator *allocator,
*/
if (!dbus_mutex_lock (allocator->lock))
return FALSE;
+ _dbus_assert (slot >= 0);
_dbus_assert (slot < allocator->n_allocated_slots);
_dbus_assert (allocator->allocated_slots[slot] == slot);
dbus_mutex_unlock (allocator->lock);
diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c
index 46e78ddd..c9a25020 100644
--- a/dbus/dbus-server-debug-pipe.c
+++ b/dbus/dbus-server-debug-pipe.c
@@ -59,13 +59,48 @@ struct DBusServerDebugPipe
dbus_bool_t disconnected; /**< TRUE if disconnect has been called */
};
+/* FIXME not threadsafe (right now the test suite doesn't use threads anyhow ) */
static DBusHashTable *server_pipe_hash;
+static int server_pipe_hash_refcount = 0;
+static dbus_bool_t
+pipe_hash_ref (void)
+{
+ if (!server_pipe_hash)
+ {
+ _dbus_assert (server_pipe_hash_refcount == 0);
+
+ server_pipe_hash = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, NULL);
+
+ if (!server_pipe_hash)
+ return FALSE;
+ }
+
+ server_pipe_hash_refcount = 1;
+
+ return TRUE;
+}
+
+static void
+pipe_hash_unref (void)
+{
+ _dbus_assert (server_pipe_hash != NULL);
+ _dbus_assert (server_pipe_hash_refcount > 0);
+
+ server_pipe_hash_refcount -= 1;
+ if (server_pipe_hash_refcount == 0)
+ {
+ _dbus_hash_table_unref (server_pipe_hash);
+ server_pipe_hash = NULL;
+ }
+}
static void
debug_finalize (DBusServer *server)
{
DBusServerDebugPipe *debug_server = (DBusServerDebugPipe*) server;
+
+ pipe_hash_unref ();
_dbus_server_finalize_base (server);
@@ -107,27 +142,23 @@ _dbus_server_debug_pipe_new (const char *server_name,
{
DBusServerDebugPipe *debug_server;
- if (!server_pipe_hash)
- {
- server_pipe_hash = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, NULL);
-
- if (!server_pipe_hash)
- {
- dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
- return NULL;
- }
- }
-
+ if (!pipe_hash_ref ())
+ return NULL;
+
if (_dbus_hash_table_lookup_string (server_pipe_hash, server_name) != NULL)
{
dbus_set_result (result, DBUS_RESULT_ADDRESS_IN_USE);
+ pipe_hash_unref ();
return NULL;
}
debug_server = dbus_new0 (DBusServerDebugPipe, 1);
if (debug_server == NULL)
- return NULL;
+ {
+ pipe_hash_unref ();
+ return NULL;
+ }
debug_server->name = _dbus_strdup (server_name);
if (debug_server->name == NULL)
@@ -136,6 +167,9 @@ _dbus_server_debug_pipe_new (const char *server_name,
dbus_free (debug_server);
dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+
+ pipe_hash_unref ();
+ return NULL;
}
if (!_dbus_server_init_base (&debug_server->base,
@@ -146,6 +180,7 @@ _dbus_server_debug_pipe_new (const char *server_name,
dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ pipe_hash_unref ();
return NULL;
}
@@ -159,6 +194,7 @@ _dbus_server_debug_pipe_new (const char *server_name,
dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ pipe_hash_unref ();
return NULL;
}