chiark / gitweb /
basic/fileio: fix memleak when discarding an invalid variable
[elogind.git] / src / basic / fileio.c
index 5b20fbb49cbb15149ad7a714876bf503b3ae604a..5cf33b48bb0cbaab5c415767916ca9ab254ef864 100644 (file)
@@ -37,6 +37,7 @@
 #include "hexdecoct.h"
 //#include "log.h"
 //#include "macro.h"
+#include "missing.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "random-util.h"
@@ -779,13 +780,12 @@ static int merge_env_file_push(
 
         if (!env_name_is_valid(key)) {
                 log_error("%s:%u: invalid variable name \"%s\", ignoring.", strna(filename), line, key);
+                free(value);
                 return 0;
         }
 
         expanded_value = replace_env(value, *env,
-                                     REPLACE_ENV_USE_ENVIRONMENT|
-                                     REPLACE_ENV_ALLOW_BRACELESS|
-                                     REPLACE_ENV_ALLOW_EXTENDED);
+                                     REPLACE_ENV_USE_ENVIRONMENT|REPLACE_ENV_ALLOW_BRACELESS);
         if (!expanded_value)
                 return -ENOMEM;
 
@@ -800,7 +800,7 @@ int merge_env_file(
                 const char *fname) {
 
         /* NOTE: this function supports braceful and braceless variable expansions,
-         * plus "extended" substitutions, unlike other exported parsing functions.
+         * unlike other exported parsing functions.
          */
 
         return parse_env_file_internal(f, fname, NEWLINE, merge_env_file_push, env, NULL);