From aa4668c792a2d363b3e19a6ee3510b7681839a0f Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 11 Oct 2021 22:28:06 +0100 Subject: [PATCH] buf.c: correctly handle unset environment variables --- src/common/buf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/common/buf.c b/src/common/buf.c index abc2b877..01070908 100644 --- a/src/common/buf.c +++ b/src/common/buf.c @@ -20,10 +20,9 @@ buf_expand_shell_variables(struct buf *s) } *p = '\0'; p = getenv(environment_variable.buf); - if (!p) { - goto out; + if (p) { + buf_add(&new, p); } - buf_add(&new, p); i += strlen(environment_variable.buf); } else if (s->buf[i] == '~') { /* expand tilde */ @@ -38,7 +37,6 @@ buf_expand_shell_variables(struct buf *s) new.buf[new.len] = '\0'; } } -out: free(environment_variable.buf); free(s->buf); s->buf = new.buf;