]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix one-time memory leak on linux
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 10 Jun 2013 18:59:39 +0000 (22:59 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 10 Jun 2013 18:59:39 +0000 (22:59 +0400)
Update #5641.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10144043

src/pkg/runtime/mem_linux.c

index 1bae755faf77615e52e551a9e2f7c29602afe7b1..bacd568d9e0c3fa642085c09ce96c09a55e986b6 100644 (file)
@@ -95,14 +95,17 @@ runtime·SysReserve(void *v, uintptr n)
        // Only user-mode Linux (UML) rejects these requests.
        if(sizeof(void*) == 8 && (uintptr)v >= 0xffffffffU) {
                p = mmap_fixed(v, 64<<10, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
-               if (p != v)
+               if (p != v) {
+                       if(p >= (void*)4096)
+                               runtime·munmap(p, 64<<10);
                        return nil;
+               }
                runtime·munmap(p, 64<<10);
                return v;
        }
-       
+
        p = runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
-       if((uintptr)p < 4096 || -(uintptr)p < 4096)
+       if((uintptr)p < 4096)
                return nil;
        return p;
 }