diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/pkg/runtime/env_posix.c | |
parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
download | golang-8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1.tar.gz |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/pkg/runtime/env_posix.c')
-rw-r--r-- | src/pkg/runtime/env_posix.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/pkg/runtime/env_posix.c b/src/pkg/runtime/env_posix.c index 00ce577d0..4c8288f6b 100644 --- a/src/pkg/runtime/env_posix.c +++ b/src/pkg/runtime/env_posix.c @@ -2,9 +2,11 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly freebsd linux netbsd openbsd windows +// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris windows #include "runtime.h" +#include "arch_GOARCH.h" +#include "malloc.h" Slice syscall·envs; @@ -44,15 +46,24 @@ void syscall·setenv_c(String k, String v) { byte *arg[2]; + uintptr len; if(_cgo_setenv == nil) return; - arg[0] = runtime·malloc(k.len + 1); + // Objects that are explicitly freed must be at least 16 bytes in size, + // so that they are not allocated using tiny alloc. + len = k.len + 1; + if(len < TinySize) + len = TinySize; + arg[0] = runtime·malloc(len); runtime·memmove(arg[0], k.str, k.len); arg[0][k.len] = 0; - arg[1] = runtime·malloc(v.len + 1); + len = v.len + 1; + if(len < TinySize) + len = TinySize; + arg[1] = runtime·malloc(len); runtime·memmove(arg[1], v.str, v.len); arg[1][v.len] = 0; |