about summary refs log tree commit diff
path: root/src/env/setenv.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-10-04 15:49:55 -0400
committerRich Felker <dalias@aerifal.cx>2013-10-04 15:49:55 -0400
commit543787039098c121917cb5f3e129d84b61afa61b (patch)
tree3c908ebf59eb31c286af668ce1f7a82274dc51a8 /src/env/setenv.c
parente5100b32d29b4249989f2423063baab3beffea06 (diff)
downloadmusl-543787039098c121917cb5f3e129d84b61afa61b.tar.gz
musl-543787039098c121917cb5f3e129d84b61afa61b.tar.xz
musl-543787039098c121917cb5f3e129d84b61afa61b.zip
fix failure to check malloc result in setenv
Diffstat (limited to 'src/env/setenv.c')
-rw-r--r--src/env/setenv.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/env/setenv.c b/src/env/setenv.c
index c2c25444..0a458968 100644
--- a/src/env/setenv.c
+++ b/src/env/setenv.c
@@ -18,14 +18,14 @@ int setenv(const char *var, const char *value, int overwrite)
 	l1 = strlen(var);
 	l2 = strlen(value);
 	s = malloc(l1+l2+2);
-	memcpy(s, var, l1);
-	s[l1] = '=';
-	memcpy(s+l1+1, value, l2);
-	s[l1+l2+1] = 0;
-	if (__putenv(s, 1)) {
-		free(s);
-		errno = ENOMEM;
-		return -1;
+	if (s) {
+		memcpy(s, var, l1);
+		s[l1] = '=';
+		memcpy(s+l1+1, value, l2);
+		s[l1+l2+1] = 0;
+		if (!__putenv(s, 1)) return 0;
 	}
-	return 0;
+	free(s);
+	errno = ENOMEM;
+	return -1;
 }