mirror of
https://github.com/golang/go
synced 2024-11-23 03:50:03 -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:
parent
1de4d313dd
commit
af375cde20
@ -1058,6 +1058,10 @@ sigind(Type *t, Typetab *tt)
|
|||||||
return p-a;
|
return p-a;
|
||||||
if((n&15) == 0){
|
if((n&15) == 0){
|
||||||
na = malloc((n+16)*sizeof(Type*));
|
na = malloc((n+16)*sizeof(Type*));
|
||||||
|
if(na == nil) {
|
||||||
|
print("%s: out of memory", argv0);
|
||||||
|
errorexit();
|
||||||
|
}
|
||||||
memmove(na, a, n*sizeof(Type*));
|
memmove(na, a, n*sizeof(Type*));
|
||||||
free(a);
|
free(a);
|
||||||
a = tt->a = na;
|
a = tt->a = na;
|
||||||
|
@ -98,6 +98,8 @@ ran(uvlong pc, uvlong epc)
|
|||||||
if(epc < oldepc) {
|
if(epc < oldepc) {
|
||||||
Range *n;
|
Range *n;
|
||||||
n = malloc(sizeof *n);
|
n = malloc(sizeof *n);
|
||||||
|
if(n == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
n->pc = epc;
|
n->pc = epc;
|
||||||
n->epc = oldepc;
|
n->epc = oldepc;
|
||||||
treeput(&breakpoints, n, n);
|
treeput(&breakpoints, n, n);
|
||||||
@ -288,6 +290,8 @@ breakpoint(uvlong pc, uvlong epc)
|
|||||||
Range *r;
|
Range *r;
|
||||||
|
|
||||||
r = malloc(sizeof *r);
|
r = malloc(sizeof *r);
|
||||||
|
if(r == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
r->pc = pc;
|
r->pc = pc;
|
||||||
r->epc = epc;
|
r->epc = epc;
|
||||||
treeput(&breakpoints, r, r);
|
treeput(&breakpoints, r, r);
|
||||||
|
@ -52,6 +52,8 @@ rwTreeNode(TreeNode *p, int color, TreeNode *left, void *key, void *value, TreeN
|
|||||||
{
|
{
|
||||||
if(p == nil)
|
if(p == nil)
|
||||||
p = malloc(sizeof *p);
|
p = malloc(sizeof *p);
|
||||||
|
if(p == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
p->color = color;
|
p->color = color;
|
||||||
p->left = left;
|
p->left = left;
|
||||||
p->key = key;
|
p->key = key;
|
||||||
|
@ -1297,6 +1297,10 @@ decodez(char *s)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = malloc(len + 1);
|
r = malloc(len + 1);
|
||||||
|
if(r == nil) {
|
||||||
|
diag("out of memory");
|
||||||
|
errorexit();
|
||||||
|
}
|
||||||
rb = r;
|
rb = r;
|
||||||
re = rb + len + 1;
|
re = rb + len + 1;
|
||||||
|
|
||||||
@ -1475,6 +1479,10 @@ inithist(Auto *a)
|
|||||||
continue;
|
continue;
|
||||||
if (linehist == 0 || linehist->absline != absline) {
|
if (linehist == 0 || linehist->absline != absline) {
|
||||||
Linehist* lh = malloc(sizeof *lh);
|
Linehist* lh = malloc(sizeof *lh);
|
||||||
|
if(lh == nil) {
|
||||||
|
diag("out of memory");
|
||||||
|
errorexit();
|
||||||
|
}
|
||||||
lh->link = linehist;
|
lh->link = linehist;
|
||||||
lh->absline = absline;
|
lh->absline = absline;
|
||||||
linehist = lh;
|
linehist = lh;
|
||||||
|
@ -399,6 +399,8 @@ addtohistogram(uvlong pc, uvlong callerpc, uvlong sp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
x = malloc(sizeof(PC));
|
x = malloc(sizeof(PC));
|
||||||
|
if(x == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
x->pc = pc;
|
x->pc = pc;
|
||||||
x->callerpc = callerpc;
|
x->callerpc = callerpc;
|
||||||
x->count = 1;
|
x->count = 1;
|
||||||
@ -617,6 +619,8 @@ findfunc(uvlong pc)
|
|||||||
return f;
|
return f;
|
||||||
|
|
||||||
f = malloc(sizeof *f);
|
f = malloc(sizeof *f);
|
||||||
|
if(f == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
memset(f, 0, sizeof *f);
|
memset(f, 0, sizeof *f);
|
||||||
f->s = s;
|
f->s = s;
|
||||||
f->next = func[h];
|
f->next = func[h];
|
||||||
@ -665,6 +669,8 @@ dumphistogram()
|
|||||||
|
|
||||||
// build array
|
// build array
|
||||||
ff = malloc(nfunc*sizeof ff[0]);
|
ff = malloc(nfunc*sizeof ff[0]);
|
||||||
|
if(ff == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
n = 0;
|
n = 0;
|
||||||
for(h = 0; h < nelem(func); h++)
|
for(h = 0; h < nelem(func); h++)
|
||||||
for(f = func[h]; f != NULL; f = f->next)
|
for(f = func[h]; f != NULL; f = f->next)
|
||||||
@ -715,6 +721,8 @@ dumppprof()
|
|||||||
return;
|
return;
|
||||||
// Allocate and link the traces together.
|
// Allocate and link the traces together.
|
||||||
trace = malloc(ntrace * sizeof(Trace));
|
trace = malloc(ntrace * sizeof(Trace));
|
||||||
|
if(trace == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
tp = trace;
|
tp = trace;
|
||||||
for(p = ppdata; p < e;) {
|
for(p = ppdata; p < e;) {
|
||||||
n = *p++;
|
n = *p++;
|
||||||
|
@ -1091,12 +1091,21 @@ machdotout(int fd, Fhdr *fp, ExecHdr *hp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmdbuf = malloc(mp->sizeofcmds);
|
cmdbuf = malloc(mp->sizeofcmds);
|
||||||
|
if(!cmdbuf) {
|
||||||
|
werrstr("out of memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
seek(fd, hdrsize, 0);
|
seek(fd, hdrsize, 0);
|
||||||
if(read(fd, cmdbuf, mp->sizeofcmds) != mp->sizeofcmds) {
|
if(read(fd, cmdbuf, mp->sizeofcmds) != mp->sizeofcmds) {
|
||||||
free(cmdbuf);
|
free(cmdbuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cmd = malloc(mp->ncmds * sizeof(MachCmd*));
|
cmd = malloc(mp->ncmds * sizeof(MachCmd*));
|
||||||
|
if(!cmd) {
|
||||||
|
free(cmdbuf);
|
||||||
|
werrstr("out of memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
cmdp = cmdbuf;
|
cmdp = cmdbuf;
|
||||||
textva = 0;
|
textva = 0;
|
||||||
textoff = 0;
|
textoff = 0;
|
||||||
|
@ -293,6 +293,8 @@ objlookup(int id, char *name, int type, uint sig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sp = malloc(sizeof(Symtab));
|
sp = malloc(sizeof(Symtab));
|
||||||
|
if(sp == nil)
|
||||||
|
sysfatal("out of memory");
|
||||||
sp->s.name = name;
|
sp->s.name = name;
|
||||||
sp->s.type = type;
|
sp->s.type = type;
|
||||||
sp->s.sig = sig;
|
sp->s.sig = sig;
|
||||||
|
Loading…
Reference in New Issue
Block a user