summaryrefslogtreecommitdiffstats
path: root/bus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-28 05:42:19 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-28 05:42:19 +0000
commitbf99381351b802fb3348a24037898222aae631e2 (patch)
treeaae0a9583e4d6aa559849e4326a3c9b2a7175015 /bus
parent574c258bc9304d51bf0cdd131a6473e6fc5b477f (diff)
2003-03-28 Havoc Pennington <hp@pobox.com>
* bus/test.c (bus_test_flush_bus): remove the sleep from here, I think it may have just been superstition. Not sure. * dbus/dbus-string.c (_dbus_string_base64_decode): catch some OOM failures that were not being handled. * dbus/dbus-auth.c (process_auth): fix a memleak in OOM handling * dbus/dbus-memory.c: add ability to set number of mallocs in a row that will fail on out-of-memory. * dbus/dbus-internals.c (_dbus_test_oom_handling): convenience function for testing out-of-memory handling. * bus/config-loader-expat.c (memsuite): don't wrap the dbus allocation functions, they do map exactly to the expat ones.
Diffstat (limited to 'bus')
-rw-r--r--bus/config-loader-expat.c24
-rw-r--r--bus/config-parser.c52
-rw-r--r--bus/dispatch.c61
-rw-r--r--bus/test.c6
4 files changed, 47 insertions, 96 deletions
diff --git a/bus/config-loader-expat.c b/bus/config-loader-expat.c
index 5e8d28c1..c7981bf4 100644
--- a/bus/config-loader-expat.c
+++ b/bus/config-loader-expat.c
@@ -25,29 +25,11 @@
#include <dbus/dbus-internals.h>
#include <expat.h>
-static void*
-expat_malloc (size_t size)
-{
- return dbus_malloc (size);
-}
-
-static void*
-expat_realloc (void *ptr, size_t size)
-{
- return dbus_realloc (ptr, size);
-}
-
-static void
-expat_free (void *ptr)
-{
- dbus_free (ptr);
-}
-
static XML_Memory_Handling_Suite memsuite =
{
- expat_malloc,
- expat_realloc,
- expat_free
+ dbus_malloc,
+ dbus_realloc,
+ dbus_free
};
typedef struct
diff --git a/bus/config-parser.c b/bus/config-parser.c
index 8fb3b29e..2429cce5 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -285,47 +285,18 @@ do_load (const DBusString *full_path,
}
}
-static dbus_bool_t
-check_oom_loading (const DBusString *full_path,
- Validity validity)
+typedef struct
{
- int approx_mallocs;
-
- /* Run once to see about how many mallocs are involved */
-
- _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
-
- if (!do_load (full_path, validity, FALSE))
- return FALSE;
+ const DBusString *full_path;
+ Validity validity;
+} LoaderOomData;
- approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
-
- _dbus_verbose ("=================\nabout %d mallocs total\n=================\n",
- approx_mallocs);
-
- approx_mallocs += 10; /* fudge factor */
-
- /* Now run failing each malloc */
-
- while (approx_mallocs >= 0)
- {
-
- _dbus_set_fail_alloc_counter (approx_mallocs);
-
- _dbus_verbose ("\n===\n(will fail malloc %d)\n===\n",
- approx_mallocs);
-
- if (!do_load (full_path, validity, TRUE))
- return FALSE;
-
- approx_mallocs -= 1;
- }
-
- _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
-
- _dbus_verbose ("=================\n all iterations passed\n=================\n");
+static dbus_bool_t
+check_loader_oom_func (void *data)
+{
+ LoaderOomData *d = data;
- return TRUE;
+ return do_load (d->full_path, d->validity, TRUE);
}
static dbus_bool_t
@@ -376,6 +347,7 @@ process_test_subdir (const DBusString *test_base_dir,
while (_dbus_directory_get_next_file (dir, &filename, &error))
{
DBusString full_path;
+ LoaderOomData d;
if (!_dbus_string_init (&full_path, _DBUS_INT_MAX))
_dbus_assert_not_reached ("couldn't init string");
@@ -407,7 +379,9 @@ process_test_subdir (const DBusString *test_base_dir,
(validity == INVALID ? "invalid" :
(validity == UNKNOWN ? "unknown" : "???")));
- if (!check_oom_loading (&full_path, validity))
+ d.full_path = &full_path;
+ d.validity = validity;
+ if (!_dbus_test_oom_handling ("config-loader", check_loader_oom_func, &d))
_dbus_assert_not_reached ("test failed");
_dbus_string_free (&full_path);
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 7db4ac29..2b1dc782 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -916,49 +916,42 @@ check_hello_connection (BusContext *context)
return TRUE;
}
-static void
-check1_try_iterations (BusContext *context,
- const char *description,
- Check1Func func)
+typedef struct
{
- int approx_mallocs;
-
- /* Run once to see about how many mallocs are involved */
-
- _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
-
- if (! (*func) (context))
- _dbus_assert_not_reached ("test failed");
+ Check1Func func;
+ BusContext *context;
+} Check1Data;
- approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
+static dbus_bool_t
+check_oom_check1_func (void *data)
+{
+ Check1Data *d = data;
- _dbus_verbose ("=================\n%s: about %d mallocs total\n=================\n",
- description, approx_mallocs);
-
- approx_mallocs += 10; /* fudge factor */
-
- /* Now run failing each malloc */
+ if (! (* d->func) (d->context))
+ return FALSE;
- while (approx_mallocs >= 0)
+ if (!check_no_leftovers (d->context))
{
- _dbus_set_fail_alloc_counter (approx_mallocs);
-
- _dbus_verbose ("\n===\n %s: (will fail malloc %d)\n===\n",
- description, approx_mallocs);
+ _dbus_warn ("Messages were left over, should be covered by test suite");
+ return FALSE;
+ }
- if (! (*func) (context))
- _dbus_assert_not_reached ("test failed");
+ return TRUE;
+}
- if (!check_no_leftovers (context))
- _dbus_assert_not_reached ("Messages were left over, should be covered by test suite");
-
- approx_mallocs -= 1;
- }
+static void
+check1_try_iterations (BusContext *context,
+ const char *description,
+ Check1Func func)
+{
+ Check1Data d;
- _dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
+ d.func = func;
+ d.context = context;
- _dbus_verbose ("=================\n%s: all iterations passed\n=================\n",
- description);
+ if (!_dbus_test_oom_handling (description, check_oom_check1_func,
+ &d))
+ _dbus_assert_not_reached ("test failed");
}
dbus_bool_t
diff --git a/bus/test.c b/bus/test.c
index 24cc6efa..ea2c3a19 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -267,7 +267,6 @@ bus_test_client_listed (DBusConnection *connection)
return FALSE;
}
-
void
bus_test_flush_bus (BusContext *context)
{
@@ -276,11 +275,14 @@ bus_test_flush_bus (BusContext *context)
* one end of the debug pipe to come out the other end...
* a more robust setup would be good. Blocking on the other
* end of pipes we've pushed data into or something.
+ * A simple hack might be to just make the debug server always
+ * poll for read on the other end of the pipe after writing.
*/
-
while (bus_loop_iterate (FALSE))
;
+#if 0
_dbus_sleep_milliseconds (15);
+#endif
while (bus_loop_iterate (FALSE))
;
}