summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/env_posix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/env_posix.c')
-rw-r--r--src/pkg/runtime/env_posix.c17
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;