summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2017-02-22 04:02:57 +0300
committerGitHub <noreply@github.com>2017-02-22 04:02:57 +0300
commitb965427b59a6912a46e1cdb26b732d3ea396b332 (patch)
tree710ebc7fae2727a95ea5c17bc49b066b851dd0c7
parent05f426d2b80cefc171fc7756bb92df8373f8145a (diff)
parent1d046f57207d6af02ba07c79b5c96eb267e61bc9 (diff)
Merge pull request #5409 from keszybz/test-env-util-memleak
test-env-util: fix typo leading to memleak
-rw-r--r--src/basic/env-util.c2
-rw-r--r--src/basic/fileio.c16
-rw-r--r--src/mount/mount-tool.c2
-rw-r--r--src/test/test-env-util.c4
4 files changed, 13 insertions, 11 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index 2ca64c3301..1ec574e8a0 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -637,7 +637,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
break;
nest--;
- if (nest == 0) { // || !strchr(e+1, '}')) {
+ if (nest == 0) {
const char *t;
_cleanup_free_ char *v = NULL;
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index b9a9f74892..7c2c2b38f5 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -554,13 +554,14 @@ static int parse_env_file_internal(
}
}
- if (state == PRE_VALUE ||
- state == VALUE ||
- state == VALUE_ESCAPE ||
- state == SINGLE_QUOTE_VALUE ||
- state == SINGLE_QUOTE_VALUE_ESCAPE ||
- state == DOUBLE_QUOTE_VALUE ||
- state == DOUBLE_QUOTE_VALUE_ESCAPE) {
+ if (IN_SET(state,
+ PRE_VALUE,
+ VALUE,
+ VALUE_ESCAPE,
+ SINGLE_QUOTE_VALUE,
+ SINGLE_QUOTE_VALUE_ESCAPE,
+ DOUBLE_QUOTE_VALUE,
+ DOUBLE_QUOTE_VALUE_ESCAPE)) {
key[n_key] = 0;
@@ -780,6 +781,7 @@ 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;
}
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c
index 4b3cac8a22..b709166aa9 100644
--- a/src/mount/mount-tool.c
+++ b/src/mount/mount-tool.c
@@ -1025,7 +1025,7 @@ static int list_devices(void) {
j = items + n++;
for (c = 0; c < _COLUMN_MAX; c++) {
- const char *x;
+ const char *x = NULL;
size_t k;
switch (c) {
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c
index 4f44cf8711..e5cc2a2df8 100644
--- a/src/test/test-env-util.c
+++ b/src/test/test-env-util.c
@@ -160,8 +160,8 @@ static void test_replace_env(bool braceless) {
q = replace_env("BARBAR=$BARBAR=${BARBAR}", (char**) env, flags);
assert_se(streq(q, braceless ? "BARBAR==" : "BARBAR=$BARBAR="));
- q = replace_env("BAR=$BAR$BAR${BAR}${BAR}", (char**) env, flags);
- assert_se(streq(q, braceless ? "BAR=waldowaldowaldowaldo" : "BAR=$BAR$BARwaldowaldo"));
+ r = replace_env("BAR=$BAR$BAR${BAR}${BAR}", (char**) env, flags);
+ assert_se(streq(r, braceless ? "BAR=waldowaldowaldowaldo" : "BAR=$BAR$BARwaldowaldo"));
p = replace_env("${BAR}$BAR$BAR", (char**) env, flags);
assert_se(streq(p, braceless ? "waldowaldowaldo" : "waldo$BAR$BAR"));