]> Cypherpunks repositories - gostls13.git/commitdiff
libmach, cmd/cc, cmd/cov, cmd/ld, cmd/prof: check malloc return value
authorShenghou Ma <minux.ma@gmail.com>
Mon, 26 Nov 2012 19:05:46 +0000 (03:05 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Mon, 26 Nov 2012 19:05:46 +0000 (03:05 +0800)
Update #4415.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6856080

src/cmd/cc/dcl.c
src/cmd/cov/main.c
src/cmd/cov/tree.c
src/cmd/ld/dwarf.c
src/cmd/prof/main.c
src/libmach/executable.c
src/libmach/obj.c

index a3ed9772da3a900722b34387d5a9d3c98959e626..edfc7e75a8d957bdd4a4a3feab02d6061cd6b4be 100644 (file)
@@ -1058,6 +1058,10 @@ sigind(Type *t, Typetab *tt)
                        return p-a;
        if((n&15) == 0){
                na = malloc((n+16)*sizeof(Type*));
+               if(na == nil) {
+                       print("%s: out of memory", argv0);
+                       errorexit();
+               }
                memmove(na, a, n*sizeof(Type*));
                free(a);
                a = tt->a = na;
index 9496632c53244454fdc5c629ef7fcc8169780cab..33ef49e17d599ee1220eba2ac80fd7e5c6444c81 100644 (file)
@@ -98,6 +98,8 @@ ran(uvlong pc, uvlong epc)
                if(epc < oldepc) {
                        Range *n;
                        n = malloc(sizeof *n);
+                       if(n == nil)
+                               sysfatal("out of memory");
                        n->pc = epc;
                        n->epc = oldepc;
                        treeput(&breakpoints, n, n);
@@ -288,6 +290,8 @@ breakpoint(uvlong pc, uvlong epc)
        Range *r;
 
        r = malloc(sizeof *r);
+       if(r == nil)
+               sysfatal("out of memory");
        r->pc = pc;
        r->epc = epc;
        treeput(&breakpoints, r, r);
index 905bb7d97851bfd938977f1397729b240233360c..366a47efd48fb297806e980e7bc29e0b0302ae4d 100644 (file)
@@ -52,6 +52,8 @@ rwTreeNode(TreeNode *p, int color, TreeNode *left, void *key, void *value, TreeN
 {
        if(p == nil)
                p = malloc(sizeof *p);
+       if(p == nil)
+               sysfatal("out of memory");
        p->color = color;
        p->left = left;
        p->key = key;
index 9c72f25db73b119b517685008cdec64b4d5139f4..bb5199fc155da0e720301c8dc1a2895b62c3fa80 100644 (file)
@@ -1297,6 +1297,10 @@ decodez(char *s)
                return 0;
 
        r = malloc(len + 1);
+       if(r == nil) {
+               diag("out of memory");
+               errorexit();
+       }
        rb = r;
        re = rb + len + 1;
 
@@ -1475,6 +1479,10 @@ inithist(Auto *a)
                        continue;
                if (linehist == 0 || linehist->absline != absline) {
                        Linehist* lh = malloc(sizeof *lh);
+                       if(lh == nil) {
+                               diag("out of memory");
+                               errorexit();
+                       }
                        lh->link = linehist;
                        lh->absline = absline;
                        linehist = lh;
index a2ae2e11e6e49acfbac6eeadc5a19fdb364946f8..e6cc836bceb58722623e33f84988b83cc95a65fd 100644 (file)
@@ -399,6 +399,8 @@ addtohistogram(uvlong pc, uvlong callerpc, uvlong sp)
                }
        }
        x = malloc(sizeof(PC));
+       if(x == nil)
+               sysfatal("out of memory");
        x->pc = pc;
        x->callerpc = callerpc;
        x->count = 1;
@@ -617,6 +619,8 @@ findfunc(uvlong pc)
                        return f;
 
        f = malloc(sizeof *f);
+       if(f == nil)
+               sysfatal("out of memory");
        memset(f, 0, sizeof *f);
        f->s = s;
        f->next = func[h];
@@ -665,6 +669,8 @@ dumphistogram()
 
        // build array
        ff = malloc(nfunc*sizeof ff[0]);
+       if(ff == nil)
+               sysfatal("out of memory");
        n = 0;
        for(h = 0; h < nelem(func); h++)
                for(f = func[h]; f != NULL; f = f->next)
@@ -715,6 +721,8 @@ dumppprof()
                return;
        // Allocate and link the traces together.
        trace = malloc(ntrace * sizeof(Trace));
+       if(trace == nil)
+               sysfatal("out of memory");
        tp = trace;
        for(p = ppdata; p < e;) {
                n = *p++;
index 3db3e7da4d98ae20eabb435dfa943048a26b28a6..3fd3e0968e76ec54f618d869498b797bdcd03580 100644 (file)
@@ -1091,12 +1091,21 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp)
        }
 
        cmdbuf = malloc(mp->sizeofcmds);
+       if(!cmdbuf) {
+               werrstr("out of memory");
+               return 0;
+       }
        seek(fd, hdrsize, 0);
        if(read(fd, cmdbuf, mp->sizeofcmds) != mp->sizeofcmds) {
                free(cmdbuf);
                return 0;
        }
        cmd = malloc(mp->ncmds * sizeof(MachCmd*));
+       if(!cmd) {
+               free(cmdbuf);
+               werrstr("out of memory");
+               return 0;
+       }
        cmdp = cmdbuf;
        textva = 0;
        textoff = 0;
index 7999f24c6eb0581362c38864541f286c2a303653..2a5e0475835e2a372fdb7bdeb46250799977f67b 100644 (file)
@@ -293,6 +293,8 @@ objlookup(int id, char *name, int type, uint sig)
                        }
        }
        sp = malloc(sizeof(Symtab));
+       if(sp == nil)
+               sysfatal("out of memory");
        sp->s.name = name;
        sp->s.type = type;
        sp->s.sig = sig;