/** * Called when about to alloc some memory; if * it returns #TRUE, then the allocation should * fail. If it returns #FALSE, then the allocation * should not fail. * * @returns #TRUE if this alloc should fail */ dbus_bool_t _dbus_decrement_fail_alloc_counter (void) { _dbus_initialize_malloc_debug (); if (fail_alloc_counter <= 0) { 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; } else { fail_alloc_counter -= 1; return FALSE; } }
/** * Called when about to alloc some memory; if * it returns #TRUE, then the allocation should * fail. If it returns #FALSE, then the allocation * should not fail. * * @returns #TRUE if this alloc should fail */ dbus_bool_t _dbus_decrement_fail_alloc_counter (void) { _dbus_initialize_malloc_debug (); #ifdef DBUS_WIN_FIXME { static dbus_bool_t called = 0; if (!called) { _dbus_verbose("TODO: memory allocation testing errors disabled for now\n"); called = 1; } return FALSE; } #endif if (fail_alloc_counter <= 0) { 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; } else { fail_alloc_counter -= 1; return FALSE; } }
/** * Aborts the program with SIGABRT (dumping core). */ void _dbus_abort (void) { const char *s; _dbus_print_backtrace (); s = _dbus_getenv ("DBUS_BLOCK_ON_ABORT"); if (s && *s) { /* don't use _dbus_warn here since it can _dbus_abort() */ fprintf (stderr, " Process %lu sleeping for gdb attach\n", _dbus_pid_for_log ()); _dbus_sleep_milliseconds (1000 * 180); } abort (); _dbus_exit (1); /* in case someone manages to ignore SIGABRT ? */ }