]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: check the value returned by runtime·SysAlloc
authorJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Fri, 1 Mar 2013 05:21:08 +0000 (00:21 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 1 Mar 2013 05:21:08 +0000 (00:21 -0500)
R=golang-dev, rsc
CC=golang-dev, minux.ma
https://golang.org/cl/7424047

src/pkg/runtime/malloc.goc
src/pkg/runtime/mgc0.c
src/pkg/runtime/mheap.c
src/pkg/runtime/mprof.goc

index b5849766c27eeb1c3e339c360cb979e1b1c1549b..ac131b3af40219946efbedab6a1a981e61864e7b 100644 (file)
@@ -519,6 +519,8 @@ runtime·settype_flush(M *mp, bool sysalloc)
                                data3 = runtime·mallocgc(nbytes3, FlagNoPointers, 0, 1);
                        } else {
                                data3 = runtime·SysAlloc(nbytes3);
+                               if(data3 == nil)
+                                       runtime·throw("runtime: cannot allocate memory");
                                if(0) runtime·printf("settype(0->3): SysAlloc(%x) --> %p\n", (uint32)nbytes3, data3);
                        }
 
@@ -555,6 +557,8 @@ runtime·settype_flush(M *mp, bool sysalloc)
                                        data2 = runtime·mallocgc(nbytes2, FlagNoPointers, 0, 1);
                                } else {
                                        data2 = runtime·SysAlloc(nbytes2);
+                                       if(data2 == nil)
+                                               runtime·throw("runtime: cannot allocate memory");
                                        if(0) runtime·printf("settype.(3->2): SysAlloc(%x) --> %p\n", (uint32)nbytes2, data2);
                                }
 
index 38ba84df406acb5a5778984349012751ada49a69..8e92d45bfa74a619b89f5eff754848b3266128df 100644 (file)
@@ -585,6 +585,8 @@ scanblock(Workbuf *wbuf, Obj *wp, uintptr nobj, bool keepworking)
 
                if(bufferList == nil) {
                        bufferList = runtime·SysAlloc(sizeof(*bufferList));
+                       if(bufferList == nil)
+                               runtime·throw("runtime: cannot allocate memory");
                        bufferList->next = nil;
                }
                scanbuffers = bufferList;
@@ -1147,6 +1149,8 @@ getempty(Workbuf *b)
                if(work.nchunk < sizeof *b) {
                        work.nchunk = 1<<20;
                        work.chunk = runtime·SysAlloc(work.nchunk);
+                       if(work.chunk == nil)
+                               runtime·throw("runtime: cannot allocate memory");
                }
                b = (Workbuf*)work.chunk;
                work.chunk += sizeof *b;
@@ -1230,6 +1234,8 @@ addroot(Obj obj)
                if(cap < 2*work.rootcap)
                        cap = 2*work.rootcap;
                new = (Obj*)runtime·SysAlloc(cap*sizeof(Obj));
+               if(new == nil)
+                       runtime·throw("runtime: cannot allocate memory");
                if(work.roots != nil) {
                        runtime·memmove(new, work.roots, work.rootcap*sizeof(Obj));
                        runtime·SysFree(work.roots, work.rootcap*sizeof(Obj));
@@ -1381,6 +1387,8 @@ handlespecial(byte *p, uintptr size)
        if(finq == nil || finq->cnt == finq->cap) {
                if(finc == nil) {
                        finc = runtime·SysAlloc(PageSize);
+                       if(finc == nil)
+                               runtime·throw("runtime: cannot allocate memory");
                        finc->cap = (PageSize - sizeof(FinBlock)) / sizeof(Finalizer) + 1;
                        finc->alllink = allfin;
                        allfin = finc;
index 76cd2011c7c1f15818e358607bb657092356623a..f45149d63f1ebd567707909ac3c0970584445d76 100644 (file)
@@ -37,6 +37,8 @@ RecordSpan(void *vh, byte *p)
                if(cap < h->nspancap*3/2)
                        cap = h->nspancap*3/2;
                all = (MSpan**)runtime·SysAlloc(cap*sizeof(all[0]));
+               if(all == nil)
+                       runtime·throw("runtime: cannot allocate memory");
                if(h->allspans) {
                        runtime·memmove(all, h->allspans, h->nspancap*sizeof(all[0]));
                        runtime·SysFree(h->allspans, h->nspancap*sizeof(all[0]));
index a99afe8bb4f1672a554f485ed836929120a7432f..ebc1e3e6616e03fe4b7c873608178833a8c681e9 100644 (file)
@@ -40,6 +40,8 @@ allocate(uintptr size)
        runtime·lock(&alloclock);
        if(size > poolfree) {
                pool = runtime·SysAlloc(Chunk);
+               if(pool == nil)
+                       runtime·throw("runtime: cannot allocate memory");
                poolfree = Chunk;
        }
        v = pool;
@@ -100,6 +102,8 @@ stkbucket(int32 typ, uintptr *stk, int32 nstk, bool alloc)
 
        if(buckhash == nil) {
                buckhash = runtime·SysAlloc(BuckHashSize*sizeof buckhash[0]);
+               if(buckhash == nil)
+                       runtime·throw("runtime: cannot allocate memory");
                mstats.buckhash_sys += BuckHashSize*sizeof buckhash[0];
        }
 
@@ -123,6 +127,8 @@ stkbucket(int32 typ, uintptr *stk, int32 nstk, bool alloc)
                return nil;
 
        b = allocate(sizeof *b + nstk*sizeof stk[0]);
+       if(b == nil)
+               runtime·throw("runtime: cannot allocate memory");
        bucketmem += sizeof *b + nstk*sizeof stk[0];
        runtime·memmove(b->stk, stk, nstk*sizeof stk[0]);
        b->typ = typ;