kernel: fix more malloc/smalloc errors

This commit is contained in:
cinap_lenrek 2011-12-12 19:17:58 +01:00
parent 304ee3b2b5
commit 8cb8043d0e
13 changed files with 34 additions and 26 deletions

View file

@ -248,7 +248,7 @@ srballoc(ulong sz)
{
Srb *srb;
srb = malloc(sizeof *srb+sz);
srb = smalloc(sizeof *srb+sz);
srb->state = Alloc;
srb->dp = srb->data = srb+1;
srb->ticksent = Ticks;
@ -260,7 +260,7 @@ srbkalloc(void *db, ulong)
{
Srb *srb;
srb = malloc(sizeof *srb);
srb = smalloc(sizeof *srb);
srb->state = Alloc;
srb->dp = srb->data = db;
srb->ticksent = Ticks;
@ -1454,7 +1454,7 @@ configwrite(Aoedev *d, void *db, long len)
if(len > sizeof d->config)
error(Etoobig);
srb = srballoc(len);
s = malloc(len);
s = smalloc(len);
memmove(s, db, len);
if(waserror()){
srbfree(srb);

View file

@ -78,6 +78,10 @@ audioreset(void)
probe = &audioprobes[i];
for(;;){
if(*pp == nil){
print("audio: no memory\n");
break;
}
memset(*pp, 0, sizeof(Audio));
(*pp)->ctlrno = ctlrno;
(*pp)->name = probe->name;

View file

@ -780,9 +780,11 @@ cachedump(Bridge *b)
Centry *ce;
char c;
buf = smalloc(n);
qlock(b);
if(waserror()) {
qunlock(b);
free(buf);
nexterror();
}
sec = TK2SEC(m->ticks);
@ -793,7 +795,6 @@ cachedump(Bridge *b)
n *= 51; // change if print format is changed
n += 10; // some slop at the end
buf = malloc(n);
p = buf;
ep = buf + n;
ce = b->cache;
@ -808,7 +809,6 @@ cachedump(Bridge *b)
*p = 0;
poperror();
qunlock(b);
return buf;
}

View file

@ -629,9 +629,7 @@ consread(Chan *c, void *buf, long n, vlong off)
return randomread(buf, n);
case Qdrivers:
b = malloc(READSTR);
if(b == nil)
error(Enomem);
b = smalloc(READSTR);
k = 0;
for(i = 0; devtab[i] != nil; i++)
k += snprint(b+k, READSTR-k, "#%C %s\n",
@ -641,8 +639,8 @@ consread(Chan *c, void *buf, long n, vlong off)
nexterror();
}
n = readstr((ulong)offset, buf, n, b);
free(b);
poperror();
free(b);
return n;
case Qzero:

View file

@ -240,7 +240,7 @@ flashread(Chan *c, void *buf, long n, vlong offset)
error(Eio);
return n;
case Qctl:
s = malloc(READSTR);
s = smalloc(READSTR);
if(waserror()){
free(s);
nexterror();
@ -475,7 +475,11 @@ addflashcard(char *name, int (*reset)(Flash*))
{
Flashtype *f, **l;
f = (Flashtype*)malloc(sizeof(*f));
f = malloc(sizeof(*f));
if(f == nil){
print("addflashcard: no memory for Flashtype\n");
return;
}
f->name = name;
f->reset = reset;
f->next = nil;

View file

@ -193,7 +193,9 @@ findcsn(int csn, int create, int dolock)
l = &c->next;
}
if(create) {
*l = nc = malloc(sizeof(Card));
if((nc = malloc(sizeof(Card))) == nil)
panic("pnp: no memory for Card");
*l = nc;
nc->next = c;
nc->csn = csn;
c = nc;

View file

@ -430,7 +430,7 @@ procopen(Chan *c, int omode)
case Qns:
if(omode != OREAD)
error(Eperm);
c->aux = malloc(sizeof(Mntwalk));
c->aux = smalloc(sizeof(Mntwalk));
break;
case Qnotepg:

View file

@ -1226,8 +1226,7 @@ sdread(Chan *c, void *a, long n, vlong off)
error(Eperm);
case Qtopctl:
m = 64*1024; /* room for register dumps */
p = buf = malloc(m);
assert(p);
p = buf = smalloc(m);
e = p + m;
qlock(&devslock);
for(i = 0; i < nelem(devs); i++){
@ -1253,7 +1252,7 @@ sdread(Chan *c, void *a, long n, vlong off)
unit = sdev->unit[UNIT(c->qid)];
m = 16*1024; /* room for register dumps */
p = malloc(m);
p = smalloc(m);
l = snprint(p, m, "inquiry %.48s\n",
(char*)unit->inquiry+8);
qlock(&unit->ctl);
@ -1790,6 +1789,8 @@ getnewport(DevConf* dc)
Devport *p;
p = malloc((dc->nports + 1) * sizeof(Devport));
if(p == nil)
panic("sd: no memory for Devport");
if(dc->nports > 0){
memmove(p, dc->ports, dc->nports * sizeof(Devport));
free(dc->ports);

View file

@ -76,7 +76,7 @@ wdread(Chan* c, void* a, long n, vlong off)
if(wd == nil || wd->stat == nil)
return 0;
p = malloc(READSTR);
p = smalloc(READSTR);
if(waserror()){
free(p);
nexterror();

View file

@ -21,7 +21,7 @@ logopen(Log *alog)
if(alog->minread == 0)
alog->minread = 1;
if(alog->buf == nil)
alog->buf = malloc(alog->nlog);
alog->buf = smalloc(alog->nlog);
alog->rptr = alog->buf;
alog->end = alog->buf + alog->nlog;
alog->len = 0;

View file

@ -212,7 +212,7 @@ netifread(Netif *nif, Chan *c, void *a, long n, ulong offset)
case Nctlqid:
return readnum(offset, a, n, NETID(c->qid.path), NUMSIZE);
case Nstatqid:
p = malloc(READSTR);
p = smalloc(READSTR);
j = snprint(p, READSTR, "in: %llud\n", nif->inpackets);
j += snprint(p+j, READSTR-j, "link: %d\n", nif->link);
j += snprint(p+j, READSTR-j, "out: %llud\n", nif->outpackets);
@ -232,7 +232,7 @@ netifread(Netif *nif, Chan *c, void *a, long n, ulong offset)
free(p);
return n;
case Naddrqid:
p = malloc(READSTR);
p = smalloc(READSTR);
j = 0;
for(i = 0; i < nif->alen; i++)
j += snprint(p+j, READSTR-j, "%2.2ux", nif->addr[i]);

View file

@ -38,10 +38,7 @@ setbootcmd(int argc, char *argv[])
char *buf, *p, *ep;
int i;
buf = malloc(1024);
if(buf == nil)
error(Enomem);
p = buf;
p = buf = smalloc(1024);
ep = buf + 1024;
for(i=0; i<argc; i++)
p = seprint(p, ep, "%q ", argv[i]);

View file

@ -45,13 +45,15 @@ initseg(void)
Image *i, *ie;
imagealloc.free = xalloc(conf.nimage*sizeof(Image));
if (imagealloc.free == nil)
panic("initseg: no memory");
if(imagealloc.free == nil)
panic("initseg: no memory for Image");
ie = &imagealloc.free[conf.nimage-1];
for(i = imagealloc.free; i < ie; i++)
i->next = i+1;
i->next = 0;
imagealloc.freechan = malloc(NFREECHAN * sizeof(Chan*));
if(imagealloc.freechan == nil)
panic("initseg: no memory for Chan");
imagealloc.szfreechan = NFREECHAN;
}