summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@centraldogma>2011-12-12 19:17:58 +0100
committercinap_lenrek <cinap_lenrek@centraldogma>2011-12-12 19:17:58 +0100
commit8cb8043d0ebeadb0d424fb1051a49573430322a3 (patch)
tree3bb91278b127dce9ebf0d30975bc7197ac2765a8
parent304ee3b2b55971d9f5f820511fb9cdadcb77b818 (diff)
kernel: fix more malloc/smalloc errors
-rw-r--r--sys/src/9/port/devaoe.c6
-rw-r--r--sys/src/9/port/devaudio.c4
-rw-r--r--sys/src/9/port/devbridge.c4
-rw-r--r--sys/src/9/port/devcons.c6
-rw-r--r--sys/src/9/port/devflash.c8
-rw-r--r--sys/src/9/port/devpnp.c4
-rw-r--r--sys/src/9/port/devproc.c2
-rw-r--r--sys/src/9/port/devsd.c7
-rw-r--r--sys/src/9/port/devwd.c2
-rw-r--r--sys/src/9/port/log.c2
-rw-r--r--sys/src/9/port/netif.c4
-rw-r--r--sys/src/9/port/rebootcmd.c5
-rw-r--r--sys/src/9/port/segment.c6
13 files changed, 34 insertions, 26 deletions
diff --git a/sys/src/9/port/devaoe.c b/sys/src/9/port/devaoe.c
index 1040b080a..63a0cd0e8 100644
--- a/sys/src/9/port/devaoe.c
+++ b/sys/src/9/port/devaoe.c
@@ -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);
diff --git a/sys/src/9/port/devaudio.c b/sys/src/9/port/devaudio.c
index c9fbcad30..fc8b39deb 100644
--- a/sys/src/9/port/devaudio.c
+++ b/sys/src/9/port/devaudio.c
@@ -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;
diff --git a/sys/src/9/port/devbridge.c b/sys/src/9/port/devbridge.c
index be416a249..6468122f9 100644
--- a/sys/src/9/port/devbridge.c
+++ b/sys/src/9/port/devbridge.c
@@ -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;
}
diff --git a/sys/src/9/port/devcons.c b/sys/src/9/port/devcons.c
index 828706f09..07c9fde27 100644
--- a/sys/src/9/port/devcons.c
+++ b/sys/src/9/port/devcons.c
@@ -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:
diff --git a/sys/src/9/port/devflash.c b/sys/src/9/port/devflash.c
index 87331ac53..28b0808e0 100644
--- a/sys/src/9/port/devflash.c
+++ b/sys/src/9/port/devflash.c
@@ -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;
diff --git a/sys/src/9/port/devpnp.c b/sys/src/9/port/devpnp.c
index 805a21303..805c614ad 100644
--- a/sys/src/9/port/devpnp.c
+++ b/sys/src/9/port/devpnp.c
@@ -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;
diff --git a/sys/src/9/port/devproc.c b/sys/src/9/port/devproc.c
index ec1e39a9e..d11937c17 100644
--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -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:
diff --git a/sys/src/9/port/devsd.c b/sys/src/9/port/devsd.c
index 38b10f6a9..d9d3fa152 100644
--- a/sys/src/9/port/devsd.c
+++ b/sys/src/9/port/devsd.c
@@ -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);
diff --git a/sys/src/9/port/devwd.c b/sys/src/9/port/devwd.c
index 30529e2f4..109285ce5 100644
--- a/sys/src/9/port/devwd.c
+++ b/sys/src/9/port/devwd.c
@@ -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();
diff --git a/sys/src/9/port/log.c b/sys/src/9/port/log.c
index 9ff1b9342..b40c7430a 100644
--- a/sys/src/9/port/log.c
+++ b/sys/src/9/port/log.c
@@ -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;
diff --git a/sys/src/9/port/netif.c b/sys/src/9/port/netif.c
index 3260a65b2..57e90c426 100644
--- a/sys/src/9/port/netif.c
+++ b/sys/src/9/port/netif.c
@@ -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]);
diff --git a/sys/src/9/port/rebootcmd.c b/sys/src/9/port/rebootcmd.c
index 591864903..6c6adf95b 100644
--- a/sys/src/9/port/rebootcmd.c
+++ b/sys/src/9/port/rebootcmd.c
@@ -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]);
diff --git a/sys/src/9/port/segment.c b/sys/src/9/port/segment.c
index 26a62998e..b48d007f1 100644
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -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;
}