diff options
author | Simon McVittie <smcv@collabora.com> | 2021-12-06 13:02:31 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2021-12-06 13:02:31 +0000 |
commit | 475a4b78a783d4be37844be6c8ffaf571b35a10d (patch) | |
tree | a5e333676f3b015256e7cbc44ae1be5f34aabc0d | |
parent | 649f46642bfbdd5bf2999041f2576737a961a24b (diff) | |
parent | 9a1f2608eea2bd8133853a0efc9c21fe7d56a8ba (diff) | |
download | dbus-475a4b78a783d4be37844be6c8ffaf571b35a10d.tar.gz |
Merge branch 'fix-issue-357' into 'master'
test-spawn-oom: Fix regression with recent Windows refactoring
Closes #357 and #279
See merge request dbus/dbus!228
-rw-r--r-- | dbus/dbus-memory.c | 12 | ||||
-rw-r--r-- | dbus/dbus-spawn-win.c | 47 |
2 files changed, 33 insertions, 26 deletions
diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index 96df2357..cee74462 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -255,18 +255,6 @@ dbus_bool_t _dbus_decrement_fail_alloc_counter (void) { _dbus_initialize_malloc_debug (); -#ifdef DBUS_WIN - { - static dbus_bool_t called = 0; - - if (!called) - { - _dbus_verbose_raw ("TODO: memory allocation testing errors disabled for now\n"); - called = 1; - } - return FALSE; - } -#endif if (fail_alloc_counter <= 0) { diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c index 86e5324c..61961901 100644 --- a/dbus/dbus-spawn-win.c +++ b/dbus/dbus-spawn-win.c @@ -368,15 +368,16 @@ protect_argv (char * const *argv, { int i; int argc = 0; + char **args = NULL; while (argv[argc]) ++argc; - *new_argv = dbus_malloc ((argc + 1) * sizeof (char *)); - if (*new_argv == NULL) + args = dbus_malloc ((argc + 1) * sizeof (char *)); + if (args == NULL) return -1; for (i = 0; i < argc; i++) - (*new_argv)[i] = NULL; + (args)[i] = NULL; /* Quote each argv element if necessary, so that it will get * reconstructed correctly in the C runtime startup code. Note that @@ -413,11 +414,13 @@ protect_argv (char * const *argv, p++; } - q = (*new_argv)[i] = dbus_malloc (len + need_dblquotes*2 + 1); + q = args[i] = dbus_malloc (len + need_dblquotes*2 + 1); if (q == NULL) - return -1; - + { + dbus_free_string_array (args); + return -1; + } p = argv[i]; @@ -443,9 +446,10 @@ protect_argv (char * const *argv, if (need_dblquotes) *q++ = '"'; *q++ = '\0'; - /* printf ("argv[%d]:%s, need_dblquotes:%s len:%d => %s\n", i, argv[i], need_dblquotes?"TRUE":"FALSE", len, (*new_argv)[i]); */ + /* printf ("argv[%d]:%s, need_dblquotes:%s len:%d => %s\n", i, argv[i], need_dblquotes?"TRUE":"FALSE", len, (args)[i]); */ } - (*new_argv)[argc] = NULL; + args[argc] = NULL; + *new_argv = args; return argc; } @@ -506,6 +510,7 @@ _dbus_spawn_program (const char *name, if (argv && argv[0]) { if (!build_commandline (argv + 1, &arg_string)) + _DBUS_SET_OOM (error); goto out; } #else @@ -643,6 +648,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, HANDLE handle; int argc; char **my_argv = NULL; + DBusError local_error = DBUS_ERROR_INIT; _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_assert (argv[0] != NULL); @@ -713,7 +719,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, _dbus_verbose ("babysitter: spawn child '%s'\n", my_argv[0]); PING(); - handle = _dbus_spawn_program (sitter->log_name, my_argv, (char **) envp, FALSE, NULL); + handle = _dbus_spawn_program (sitter->log_name, my_argv, (char **) envp, FALSE, &local_error); if (my_argv != NULL) { @@ -723,13 +729,26 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, PING(); if (handle == NULL) { - sitter->child_handle = NULL; - sitter->have_spawn_errno = TRUE; - sitter->spawn_errno = GetLastError(); - dbus_set_error_const (error, DBUS_ERROR_SPAWN_EXEC_FAILED, - "Failed to spawn child"); + if (dbus_error_has_name (&local_error, DBUS_ERROR_NO_MEMORY)) + { + sitter->child_handle = NULL; + sitter->have_spawn_errno = TRUE; + sitter->spawn_errno = ERROR_NOT_ENOUGH_MEMORY; + dbus_move_error (&local_error, error); + } + else + { + sitter->child_handle = NULL; + sitter->have_spawn_errno = TRUE; + sitter->spawn_errno = GetLastError(); + dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED, + "Failed to spawn child: %s", local_error.message); + } + dbus_error_free (&local_error); goto out0; } + else + dbus_error_free (&local_error); sitter->child_handle = handle; |