From: Zbigniew Jędrzejewski-Szmek Date: Tue, 19 Mar 2024 22:36:03 +0000 (+0100) Subject: oomd: use strdup_to() and RET_GATHER() X-Git-Tag: v256-rc1~459^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8486f2592d4ec330f66f27857334f65c713ef40;p=thirdparty%2Fsystemd.git oomd: use strdup_to() and RET_GATHER() --- diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 6e6678c33d9..69d103e71f0 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -321,17 +321,16 @@ int oomd_kill_by_pgscan_rate(Hashmap *h, const char *prefix, bool dry_run, char if (r == -ENOMEM) return r; /* Treat oom as a hard error */ if (r < 0) { - if (ret == 0) - ret = r; + RET_GATHER(ret, r); continue; /* Try to find something else to kill */ } dump_until = MAX(dump_until, i + 1); - char *selected = strdup(sorted[i]->path); - if (!selected) - return -ENOMEM; - *ret_selected = selected; + ret = r; + r = strdup_to(ret_selected, sorted[i]->path); + if (r < 0) + return r; break; } @@ -365,17 +364,16 @@ int oomd_kill_by_swap_usage(Hashmap *h, uint64_t threshold_usage, bool dry_run, if (r == -ENOMEM) return r; /* Treat oom as a hard error */ if (r < 0) { - if (ret == 0) - ret = r; + RET_GATHER(ret, r); continue; /* Try to find something else to kill */ } dump_until = MAX(dump_until, i + 1); - char *selected = strdup(sorted[i]->path); - if (!selected) - return -ENOMEM; - *ret_selected = selected; + ret = r; + r = strdup_to(ret_selected, sorted[i]->path); + if (r < 0) + return r; break; } @@ -442,9 +440,9 @@ int oomd_cgroup_context_acquire(const char *path, OomdCGroupContext **ret) { return log_debug_errno(r, "Error converting pgscan value to uint64_t: %m"); } - ctx->path = strdup(empty_to_root(path)); - if (!ctx->path) - return -ENOMEM; + r = strdup_to(&ctx->path, empty_to_root(path)); + if (r < 0) + return r; *ret = TAKE_PTR(ctx); return 0;