From bf99381351b802fb3348a24037898222aae631e2 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 28 Mar 2003 05:42:19 +0000 Subject: 2003-03-28 Havoc Pennington * 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. --- bus/dispatch.c | 61 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) (limited to 'bus/dispatch.c') 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 -- cgit