2006-10-23 David Zeuthen <davidz@redhat.com>

* dbus/dbus-memory.c: Use atomic variable to protect
        n_blocks_outstanding otherwise OOM will be reported using SMP on
        some arches

        * bus/dispatch.c: Add missing end of line characters

        * bus/desktop-file.c (parse_section_start, parse_key_value)
        (bus_desktop_file_load): Propertly handle OOM

        * dbus/dbus-threads.c (init_uninitialized_locks): Check that
        thread_init_generation equals _dbus_current_generation, not 0
This commit is contained in:
David Zeuthen 2006-10-23 17:25:52 +00:00
parent 8ea5a53324
commit cb905b58f0
5 changed files with 57 additions and 32 deletions

View file

@ -1,3 +1,17 @@
2006-10-23 David Zeuthen <davidz@redhat.com>
* dbus/dbus-memory.c: Use atomic variable to protect
n_blocks_outstanding otherwise OOM will be reported using SMP on
some arches
* bus/dispatch.c: Add missing end of line characters
* bus/desktop-file.c (parse_section_start, parse_key_value)
(bus_desktop_file_load): Propertly handle OOM
* dbus/dbus-threads.c (init_uninitialized_locks): Check that
thread_init_generation equals _dbus_current_generation, not 0
2006-10-22 Havoc Pennington <hp@redhat.com>
* dbus/dbus-connection-internal.h: move prototype of

View file

@ -430,6 +430,8 @@ parse_section_start (BusDesktopFileParser *parser, DBusError *error)
if (open_section (parser, section_name) == NULL)
{
dbus_free (section_name);
parser_free (parser);
BUS_SET_OOM (error);
return FALSE;
}
@ -527,6 +529,7 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)
{
dbus_free (value);
parser_free (parser);
BUS_SET_OOM (error);
return FALSE;
}
@ -534,21 +537,26 @@ parse_key_value (BusDesktopFileParser *parser, DBusError *error)
{
dbus_free (value);
parser_free (parser);
BUS_SET_OOM (error);
return FALSE;
}
if (!_dbus_string_copy_len (&parser->data, key_start, key_end - key_start,
&key, 0))
{
_dbus_string_free (&key);
dbus_free (value);
parser_free (parser);
BUS_SET_OOM (error);
return FALSE;
}
if (!_dbus_string_steal_data (&key, &tmp))
{
_dbus_string_free (&key);
dbus_free (value);
parser_free (parser);
BUS_SET_OOM (error);
return FALSE;
}
@ -633,7 +641,10 @@ bus_desktop_file_load (DBusString *filename,
}
if (!_dbus_string_init (&str))
return NULL;
{
BUS_SET_OOM (error);
return NULL;
}
if (!_dbus_file_get_contents (&str, filename, error))
{

View file

@ -581,7 +581,7 @@ check_service_owner_changed_foreach (DBusConnection *connection,
|| (d->expected_kind == OWNER_CHANGED && (!old_owner[0] || !new_owner[0]))
|| (d->expected_kind == SERVICE_DELETED && (!old_owner[0] || new_owner[0])))
{
_dbus_warn ("inconsistent NameOwnerChanged arguments");
_dbus_warn ("inconsistent NameOwnerChanged arguments\n");
goto out;
}
@ -2359,7 +2359,7 @@ check_got_service_info (DBusMessage *message)
}
else
{
_dbus_warn ("unexpected arguments for NameOwnerChanged message");
_dbus_warn ("unexpected arguments for NameOwnerChanged message\n");
message_kind = GOT_SOMETHING_ELSE;
}
}
@ -2556,12 +2556,13 @@ check_existent_service_no_auto_start (BusContext *context,
if (message_kind != GOT_ERROR)
{
block_connection_until_message_from_bus (context, connection, "error about service exiting");
/* and process everything again */
bus_test_run_everything (context);
if (!check_got_error (context, connection,
DBUS_ERROR_SPAWN_CHILD_EXITED,
DBUS_ERROR_NO_MEMORY,
NULL))
goto out;
}
@ -3109,7 +3110,7 @@ check_existent_service_auto_start (BusContext *context,
if (message == NULL)
{
_dbus_warn ("No message after auto activation "
"(should be a service announcement)");
"(should be a service announcement)\n");
dbus_connection_return_message (connection, message);
message = NULL;
goto out;
@ -3398,7 +3399,7 @@ check_shell_service_success_auto_start (BusContext *context,
if (message == NULL)
{
_dbus_warn ("No message after auto activation "
"(should be a service announcement)");
"(should be a service announcement)\n");
dbus_connection_return_message (connection, message);
message = NULL;
goto out;
@ -3489,7 +3490,7 @@ check_shell_service_success_auto_start (BusContext *context,
DBUS_TYPE_STRING, &argv[6],
DBUS_TYPE_INVALID))
{
_dbus_warn ("Error getting arguments from return");
_dbus_warn ("Error getting arguments from return\n");
goto out;
}
@ -3498,42 +3499,42 @@ check_shell_service_success_auto_start (BusContext *context,
*/
if (strcmp("-test", argv[1]) != 0)
{
_dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)",
_dbus_warn ("Unexpected argv[1] in shell success service test (expected: %s, got: %s)\n",
"-test", argv[1]);
goto out;
}
if (strcmp("that", argv[2]) != 0)
{
_dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)",
_dbus_warn ("Unexpected argv[2] in shell success service test (expected: %s, got: %s)\n",
"that", argv[2]);
goto out;
}
if (strcmp("we get", argv[3]) != 0)
{
_dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)",
_dbus_warn ("Unexpected argv[3] in shell success service test (expected: %s, got: %s)\n",
"we get", argv[3]);
goto out;
}
if (strcmp("back", argv[4]) != 0)
{
_dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)",
_dbus_warn ("Unexpected argv[4] in shell success service test (expected: %s, got: %s)\n",
"back", argv[4]);
goto out;
}
if (strcmp("--what", argv[5]) != 0)
{
_dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)",
_dbus_warn ("Unexpected argv[5] in shell success service test (expected: %s, got: %s)\n",
"--what", argv[5]);
goto out;
}
if (strcmp("we put in", argv[6]) != 0)
{
_dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)",
_dbus_warn ("Unexpected argv[6] in shell success service test (expected: %s, got: %s)\n",
"we put in", argv[6]);
goto out;
}
@ -3880,7 +3881,7 @@ check_list_services (BusContext *context,
case GOT_ERROR:
case GOT_SERVICE_DELETED:
_dbus_warn ("Unexpected message after ActivateService "
"(should be an error or a service announcement");
"(should be an error or a service announcement)\n");
goto out;
case GOT_SERVICE_CREATED:
@ -3955,7 +3956,7 @@ check_oom_check2_func (void *data)
if (!check_no_leftovers (d->context))
{
_dbus_warn ("Messages were left over, should be covered by test suite");
_dbus_warn ("Messages were left over, should be covered by test suite\n");
return FALSE;
}
@ -4057,7 +4058,7 @@ bus_dispatch_test (const DBusString *test_data_dir)
if (!check_no_leftovers (context))
{
_dbus_warn ("Messages were left over after setting up initial connections");
_dbus_warn ("Messages were left over after setting up initial connections\n");
_dbus_assert_not_reached ("initial connection setup failed");
}

View file

@ -105,7 +105,7 @@ 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;
static int n_blocks_outstanding = 0;
static DBusAtomic n_blocks_outstanding = {0};
/** value stored in guard padding for debugging buffer overrun */
#define GUARD_VALUE 0xdeadbeef
@ -283,7 +283,7 @@ _dbus_decrement_fail_alloc_counter (void)
int
_dbus_get_malloc_blocks_outstanding (void)
{
return n_blocks_outstanding;
return n_blocks_outstanding.value;
}
/**
@ -445,11 +445,10 @@ dbus_malloc (size_t bytes)
if (_dbus_decrement_fail_alloc_counter ())
{
_dbus_verbose (" FAILING malloc of %ld bytes\n", (long) bytes);
return NULL;
}
#endif
if (bytes == 0) /* some system mallocs handle this, some don't */
return NULL;
#ifdef DBUS_BUILD_TESTS
@ -461,7 +460,7 @@ dbus_malloc (size_t bytes)
block = malloc (bytes + GUARD_EXTRA_SIZE);
if (block)
n_blocks_outstanding += 1;
_dbus_atomic_inc (&n_blocks_outstanding);
return set_guards (block, bytes, SOURCE_MALLOC);
}
@ -472,7 +471,7 @@ dbus_malloc (size_t bytes)
mem = malloc (bytes);
#ifdef DBUS_BUILD_TESTS
if (mem)
n_blocks_outstanding += 1;
_dbus_atomic_inc (&n_blocks_outstanding);
#endif
return mem;
}
@ -503,7 +502,7 @@ dbus_malloc0 (size_t bytes)
return NULL;
}
#endif
if (bytes == 0)
return NULL;
#ifdef DBUS_BUILD_TESTS
@ -515,7 +514,7 @@ dbus_malloc0 (size_t bytes)
block = calloc (bytes + GUARD_EXTRA_SIZE, 1);
if (block)
n_blocks_outstanding += 1;
_dbus_atomic_inc (&n_blocks_outstanding);
return set_guards (block, bytes, SOURCE_MALLOC_ZERO);
}
#endif
@ -525,7 +524,7 @@ dbus_malloc0 (size_t bytes)
mem = calloc (bytes, 1);
#ifdef DBUS_BUILD_TESTS
if (mem)
n_blocks_outstanding += 1;
_dbus_atomic_inc (&n_blocks_outstanding);
#endif
return mem;
}
@ -590,7 +589,7 @@ dbus_realloc (void *memory,
block = malloc (bytes + GUARD_EXTRA_SIZE);
if (block)
n_blocks_outstanding += 1;
_dbus_atomic_inc (&n_blocks_outstanding);
return set_guards (block, bytes, SOURCE_REALLOC_NULL);
}
@ -602,7 +601,7 @@ dbus_realloc (void *memory,
mem = realloc (memory, bytes);
#ifdef DBUS_BUILD_TESTS
if (memory == NULL && mem != NULL)
n_blocks_outstanding += 1;
_dbus_atomic_inc (&n_blocks_outstanding);
#endif
return mem;
}
@ -623,9 +622,9 @@ dbus_free (void *memory)
check_guards (memory, TRUE);
if (memory)
{
n_blocks_outstanding -= 1;
_dbus_atomic_dec (&n_blocks_outstanding);
_dbus_assert (n_blocks_outstanding >= 0);
_dbus_assert (n_blocks_outstanding.value >= 0);
free (((unsigned char*)memory) - GUARD_START_OFFSET);
}
@ -637,9 +636,9 @@ dbus_free (void *memory)
if (memory) /* we guarantee it's safe to free (NULL) */
{
#ifdef DBUS_BUILD_TESTS
n_blocks_outstanding -= 1;
_dbus_atomic_dec (&n_blocks_outstanding);
_dbus_assert (n_blocks_outstanding >= 0);
_dbus_assert (n_blocks_outstanding.value >= 0);
#endif
free (memory);

View file

@ -350,7 +350,7 @@ init_uninitialized_locks (void)
{
DBusList *link;
_dbus_assert (thread_init_generation == 0);
_dbus_assert (thread_init_generation == _dbus_current_generation);
link = uninitialized_mutex_list;
while (link != NULL)