summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-memory.c
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 /dbus/dbus-memory.c
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 'dbus/dbus-memory.c')
-rw-r--r--dbus/dbus-memory.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c
index 983c6e31..11d52045 100644
--- a/dbus/dbus-memory.c
+++ b/dbus/dbus-memory.c
@@ -76,9 +76,11 @@
#ifdef DBUS_BUILD_TESTS
static dbus_bool_t debug_initialized = FALSE;
-static int fail_counts = -1;
+static int fail_nth = -1;
static size_t fail_size = 0;
static int fail_alloc_counter = _DBUS_INT_MAX;
+static int n_failures_per_failure = 1;
+static int n_failures_this_failure = 0;
static dbus_bool_t guards = FALSE;
static dbus_bool_t disable_mem_pools = FALSE;
static dbus_bool_t backtrace_on_fail_alloc = FALSE;
@@ -106,9 +108,9 @@ _dbus_initialize_malloc_debug (void)
if (_dbus_getenv ("DBUS_MALLOC_FAIL_NTH") != NULL)
{
- fail_counts = atoi (_dbus_getenv ("DBUS_MALLOC_FAIL_NTH"));
- fail_alloc_counter = fail_counts;
- _dbus_verbose ("Will fail malloc every %d times\n", fail_counts);
+ fail_nth = atoi (_dbus_getenv ("DBUS_MALLOC_FAIL_NTH"));
+ fail_alloc_counter = fail_nth;
+ _dbus_verbose ("Will fail malloc every %d times\n", fail_nth);
}
if (_dbus_getenv ("DBUS_MALLOC_FAIL_GREATER_THAN") != NULL)
@@ -185,6 +187,30 @@ _dbus_get_fail_alloc_counter (void)
}
/**
+ * Sets how many mallocs to fail when the fail alloc counter reaches
+ * 0.
+ *
+ * @param number to fail
+ */
+void
+_dbus_set_fail_alloc_failures (int failures_per_failure)
+{
+ n_failures_per_failure = failures_per_failure;
+}
+
+/**
+ * Gets the number of failures we'll have when the fail malloc
+ * counter reaches 0.
+ *
+ * @returns number of failures planned
+ */
+int
+_dbus_get_fail_alloc_failures (void)
+{
+ return n_failures_per_failure;
+}
+
+/**
* Called when about to alloc some memory; if
* it returns #TRUE, then the allocation should
* fail. If it returns #FALSE, then the allocation
@@ -199,14 +225,23 @@ _dbus_decrement_fail_alloc_counter (void)
if (fail_alloc_counter <= 0)
{
- if (fail_counts >= 0)
- fail_alloc_counter = fail_counts;
- else
- fail_alloc_counter = _DBUS_INT_MAX;
-
- _dbus_verbose ("reset fail alloc counter to %d\n", fail_alloc_counter);
if (backtrace_on_fail_alloc)
_dbus_print_backtrace ();
+
+ _dbus_verbose ("failure %d\n", n_failures_this_failure);
+
+ n_failures_this_failure += 1;
+ if (n_failures_this_failure >= n_failures_per_failure)
+ {
+ if (fail_nth >= 0)
+ fail_alloc_counter = fail_nth;
+ else
+ fail_alloc_counter = _DBUS_INT_MAX;
+
+ n_failures_this_failure = 0;
+
+ _dbus_verbose ("reset fail alloc counter to %d\n", fail_alloc_counter);
+ }
return TRUE;
}