]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix GOTRACEBACK on Plan 9
authorDavid du Colombier <0intro@gmail.com>
Wed, 9 Apr 2014 04:41:14 +0000 (06:41 +0200)
committerDavid du Colombier <0intro@gmail.com>
Wed, 9 Apr 2014 04:41:14 +0000 (06:41 +0200)
Getenv() should not call malloc when called from
gotraceback(). Instead, we return a static buffer
in this case, with enough room to hold the longest
value.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/85680043

src/pkg/runtime/env_plan9.c

index 599319c755022c4cddd2f262564d93d851f6d429..f732c9f294ee3d22545a3d2bd98d3a0cdca672d8 100644 (file)
@@ -12,6 +12,7 @@ runtime·getenv(int8 *s)
        intgo len;
        byte file[128];
        byte *p;
+       static byte b[128];
 
        len = runtime·findnull((byte*)s);
        if(len > sizeof file-6)
@@ -25,7 +26,14 @@ runtime·getenv(int8 *s)
        if(fd < 0)
                return nil;
        n = runtime·seek(fd, 0, 2);
-       p = runtime·malloc(n+1);
+       if(runtime·strcmp((byte*)s, (byte*)"GOTRACEBACK") == 0){
+               // should not call malloc
+               if(n >= sizeof b)
+                       return nil;
+               runtime·memclr(b, sizeof b);
+               p = b;
+       }else
+               p = runtime·malloc(n+1);
        r = runtime·pread(fd, p, n, 0);
        runtime·close(fd);
        if(r < 0)