1
0
mirror of https://github.com/golang/go synced 2024-11-26 20:11:26 -07:00

libmach, cmd/cc, cmd/cov, cmd/ld, cmd/prof: check malloc return value

Update #4415.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6856080
This commit is contained in:
Shenghou Ma 2012-11-27 03:05:46 +08:00
parent 1de4d313dd
commit af375cde20
7 changed files with 37 additions and 0 deletions

View 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;

View 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);

View 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;

View 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;

View 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++;

View 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;

View 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;