diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-03-19 20:34:42 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-03-20 15:18:21 +0100 |
commit | 418b936d477e29b9a95316ad3d9b247ef462ec89 (patch) | |
tree | 01a3fa7089e554de4cc627093cc1a532a283be4b /src/basic/path-lookup.c | |
parent | various: use strdup_to() in various obvious cases (diff) | |
download | systemd-418b936d477e29b9a95316ad3d9b247ef462ec89.tar.xz systemd-418b936d477e29b9a95316ad3d9b247ef462ec89.zip |
various: use strdup_to() after getenv()
Diffstat (limited to 'src/basic/path-lookup.c')
-rw-r--r-- | src/basic/path-lookup.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c index e7fc4a7f06..540256b73b 100644 --- a/src/basic/path-lookup.c +++ b/src/basic/path-lookup.c @@ -92,7 +92,6 @@ int xdg_user_data_dir(char **ret, const char *suffix) { } int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) { - _cleanup_free_ char *d = NULL; int r; assert(ret); @@ -106,26 +105,20 @@ int runtime_directory(char **ret, RuntimeScope scope, const char *suffix) { * Return value indicates whether the suffix was applied or not */ const char *e = secure_getenv("RUNTIME_DIRECTORY"); - if (e) { - d = strdup(e); - if (!d) - return -ENOMEM; - - *ret = TAKE_PTR(d); - return false; - } + if (e) + return strdup_to(ret, e); if (scope == RUNTIME_SCOPE_USER) { - r = xdg_user_runtime_dir(&d, suffix); + r = xdg_user_runtime_dir(ret, suffix); if (r < 0) return r; } else { - d = path_join("/run", suffix); + char *d = path_join("/run", suffix); if (!d) return -ENOMEM; + *ret = d; } - *ret = TAKE_PTR(d); return true; } |