From 838c0214aa658a93981fb3dcff04c1b9d25983f7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 25 Mar 2020 00:38:34 -0400 Subject: Fix a few memory leaks: * Cannot free array of manifests successfully though... TODO --- lib/environment.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/environment.c') diff --git a/lib/environment.c b/lib/environment.c index d9bfe51..3144982 100644 --- a/lib/environment.c +++ b/lib/environment.c @@ -250,18 +250,20 @@ char *runtime_expand_var(RuntimeEnv *env, const char *input) { const char delim = '$'; const char *delim_literal = "$$"; const char *escape = "\\"; - char *expanded = calloc(BUFSIZ, sizeof(char)); - if (expanded == NULL) { - perror("could not allocate runtime_expand_var buffer"); - fprintf(SYSERROR); - return NULL; - } + char *expanded = NULL; // If there's no environment variables to process return a copy of the input string if (strchr(input, delim) == NULL) { return strdup(input); } + expanded = calloc(BUFSIZ, sizeof(char)); + if (expanded == NULL) { + perror("could not allocate runtime_expand_var buffer"); + fprintf(SYSERROR); + return NULL; + } + // Parse the input string size_t i; for (i = 0; i < strlen(input); i++) { -- cgit