From cbc165d17ef571d9b7f2b768603abef84e726bb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Jun 2021 16:46:35 +0200 Subject: [PATCH] core/serialization: shorten code, treat all oom error the same --- src/core/execute.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 5c30d0bcbe6..8450bb05552 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -6371,38 +6371,24 @@ int exec_runtime_deserialize_compat(Unit *u, const char *key, const char *value, return 0; } - r = hashmap_ensure_allocated(&u->manager->exec_runtime_by_id, &string_hash_ops); - if (r < 0) { - log_unit_debug_errno(u, r, "Failed to allocate storage for runtime parameter: %m"); - return 0; - } + if (hashmap_ensure_allocated(&u->manager->exec_runtime_by_id, &string_hash_ops) < 0) + return log_oom(); rt = hashmap_get(u->manager->exec_runtime_by_id, u->id); if (!rt) { - r = exec_runtime_allocate(&rt_create, u->id); - if (r < 0) + if (exec_runtime_allocate(&rt_create, u->id) < 0) return log_oom(); rt = rt_create; } if (streq(key, "tmp-dir")) { - char *copy; - - copy = strdup(value); - if (!copy) - return log_oom(); - - free_and_replace(rt->tmp_dir, copy); + if (free_and_strdup_warn(&rt->tmp_dir, value) < 0) + return -ENOMEM; } else if (streq(key, "var-tmp-dir")) { - char *copy; - - copy = strdup(value); - if (!copy) - return log_oom(); - - free_and_replace(rt->var_tmp_dir, copy); + if (free_and_strdup_warn(&rt->var_tmp_dir, value) < 0) + return -ENOMEM; } else if (streq(key, "netns-socket-0")) { int fd; -- 2.47.3