summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/posix/environment_posix.c1
-rw-r--r--test/test_environment.c3
2 files changed, 4 insertions, 0 deletions
diff --git a/src/posix/environment_posix.c b/src/posix/environment_posix.c
index 32a1c8d..8447753 100644
--- a/src/posix/environment_posix.c
+++ b/src/posix/environment_posix.c
@@ -100,6 +100,7 @@ zix_expand_environment_strings(ZixAllocator* const allocator,
!(ref = set_ref(allocator, &ref, t, string + s)) ||
!(out = append_var(allocator, &len, out, t, ref))) {
zix_free(allocator, ref);
+ zix_free(allocator, out);
return NULL;
}
start = s = t;
diff --git a/test/test_environment.c b/test/test_environment.c
index dba7b90..8756441 100644
--- a/test/test_environment.c
+++ b/test/test_environment.c
@@ -111,6 +111,9 @@ test_failed_alloc(void)
zix_failing_allocator_reset(&allocator, 2U);
assert(!zix_expand_environment_strings(&allocator.base, "/one:$HOME/two"));
+
+ zix_failing_allocator_reset(&allocator, 1U);
+ assert(!zix_expand_environment_strings(&allocator.base, "/one:$UNSET/two"));
#endif
}