summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-01-25 01:26:49 +0000
committerHavoc Pennington <hp@redhat.com>2003-01-25 01:26:49 +0000
commita1a53c32422230fb76e8e3bca67c877dd2857563 (patch)
tree7b9b348cee61d6ba6ec7595df5e0b0cc3e9d32ed
parenta284b8071436e02064074e08d56dfcc6702c5250 (diff)
2003-01-24 Havoc Pennington <hp@pobox.com>
* dbus/dbus-list.c (alloc_link): put a thread lock on the global list_pool * bus/driver.c (bus_driver_handle_list_services): fix a leak on OOM
-rw-r--r--ChangeLog8
-rw-r--r--bus/driver.c11
-rw-r--r--dbus/dbus-list.c22
3 files changed, 36 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 2fedb455..92cfe5e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-01-24 Havoc Pennington <hp@pobox.com>
+
+ * dbus/dbus-list.c (alloc_link): put a thread lock on the global
+ list_pool
+
+ * bus/driver.c (bus_driver_handle_list_services): fix a leak
+ on OOM
+
2003-01-25 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-list.c: (alloc_link), (free_link):
diff --git a/bus/driver.c b/bus/driver.c
index da167bbe..eacca934 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -248,7 +248,7 @@ bus_driver_handle_list_services (DBusConnection *connection,
services = bus_services_list (&len);
if (!services)
- return;
+ goto error;
if (!dbus_message_append_fields (reply,
DBUS_TYPE_STRING_ARRAY, services, len,
@@ -260,9 +260,12 @@ bus_driver_handle_list_services (DBusConnection *connection,
error:
dbus_message_unref (reply);
- for (i = 0; i < len; i++)
- dbus_free (services[i]);
- dbus_free (services);
+ if (services != NULL)
+ {
+ for (i = 0; i < len; i++)
+ dbus_free (services[i]);
+ dbus_free (services);
+ }
}
/* This is where all the magic occurs */
diff --git a/dbus/dbus-list.c b/dbus/dbus-list.c
index 42fc79bf..546da5cd 100644
--- a/dbus/dbus-list.c
+++ b/dbus/dbus-list.c
@@ -24,6 +24,7 @@
#include "dbus-internals.h"
#include "dbus-list.h"
#include "dbus-mempool.h"
+#include "dbus-threads.h"
/**
* @defgroup DBusList Linked list
@@ -34,6 +35,7 @@
*/
static DBusMemPool *list_pool;
+static DBusStaticMutex list_pool_lock = DBUS_STATIC_MUTEX_INIT;
/**
* @defgroup DBusListInternals Linked list implementation details
@@ -45,16 +47,32 @@ static DBusMemPool *list_pool;
* @{
*/
+/* the mem pool is probably a speed hit, with the thread
+ * lock, though it does still save memory - unknown.
+ */
static DBusList*
alloc_link (void *data)
{
DBusList *link;
+ if (!dbus_static_mutex_lock (&list_pool_lock))
+ return NULL;
+
if (!list_pool)
- list_pool = _dbus_mem_pool_new (sizeof (DBusList), TRUE);
+ {
+ list_pool = _dbus_mem_pool_new (sizeof (DBusList), TRUE);
+ if (list_pool == NULL)
+ {
+ dbus_static_mutex_unlock (&list_pool_lock);
+ return NULL;
+ }
+ }
+
link = _dbus_mem_pool_alloc (list_pool);
link->data = data;
+
+ dbus_static_mutex_unlock (&list_pool_lock);
return link;
}
@@ -62,7 +80,9 @@ alloc_link (void *data)
static void
free_link (DBusList *link)
{
+ dbus_static_mutex_lock (&list_pool_lock);
_dbus_mem_pool_dealloc (list_pool, link);
+ dbus_static_mutex_unlock (&list_pool_lock);
}
static void