summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
authorenami <enami@NetBSD.org>2009-12-02 09:34:51 +0000
committerenami <enami@NetBSD.org>2009-12-02 09:34:51 +0000
commit8f4cd2bee8acda568375e7a8f13bb3d2698df826 (patch)
treed242e5e071caa700ff59cc9f3e67ef33986a6506 /lib/libc/stdlib/setenv.c
parent7cfa046806c0090bf9f6731c7bba313914765e8b (diff)
Retain old variables when failed to allocate memory.
Diffstat (limited to 'lib/libc/stdlib/setenv.c')
-rw-r--r--lib/libc/stdlib/setenv.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index 5aaf627dd90..0337fb267c2 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -1,4 +1,4 @@
-/* $NetBSD: setenv.c,v 1.31 2008/11/01 00:54:47 christos Exp $ */
+/* $NetBSD: setenv.c,v 1.32 2009/12/02 09:34:51 enami Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: setenv.c,v 1.31 2008/11/01 00:54:47 christos Exp $");
+__RCSID("$NetBSD: setenv.c,v 1.32 2009/12/02 09:34:51 enami Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -103,9 +103,9 @@ setenv(const char *name, const char *value, int rewrite)
continue;
size = cc - name;
/* name + `=' + value */
- if ((environ[offset] = malloc(size + l_value + 2)) == NULL)
+ if ((c = malloc(size + l_value + 2)) == NULL)
goto bad;
- c = environ[offset];
+ environ[offset] = c;
(void)memcpy(c, name, size);
c += size;
*c++ = '=';