From cb4499d0056a7c974d7d3695cc355c7e77edc938 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 11 Feb 2017 13:22:13 -0500 Subject: basic/env-util: use _cleanup_ in replace_env() --- src/basic/env-util.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 99a130008b..8774a81531 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -527,7 +527,8 @@ char *replace_env(const char *format, char **env, unsigned flags) { } state = WORD; const char *e, *word = format; - char *r = NULL, *k; + char *k; + _cleanup_free_ char *r = NULL; assert(format); @@ -544,7 +545,7 @@ char *replace_env(const char *format, char **env, unsigned flags) { if (*e == '{') { k = strnappend(r, word, e-word-1); if (!k) - goto fail; + return NULL; free(r); r = k; @@ -555,7 +556,7 @@ char *replace_env(const char *format, char **env, unsigned flags) { } else if (*e == '$') { k = strnappend(r, word, e-word); if (!k) - goto fail; + return NULL; free(r); r = k; @@ -574,7 +575,7 @@ char *replace_env(const char *format, char **env, unsigned flags) { k = strappend(r, t); if (!k) - goto fail; + return NULL; free(r); r = k; @@ -586,15 +587,7 @@ char *replace_env(const char *format, char **env, unsigned flags) { } } - k = strnappend(r, word, e-word); - if (!k) - goto fail; - - free(r); - return k; - -fail: - return mfree(r); + return strnappend(r, word, e-word); } char **replace_env_argv(char **argv, char **env) { -- cgit v1.2.3-54-g00ecf