check error return from malloc and bail.

This commit is contained in:
christos 2004-12-21 16:20:09 +00:00
parent ce14df22e4
commit 03cbcf1149
4 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: stree.c,v 1.6 2002/07/10 20:19:44 wiz Exp $ */ /* $NetBSD: stree.c,v 1.7 2004/12/21 16:20:09 christos Exp $ */
/* /*
* Copyright (c) 1992 Carnegie Mellon University * Copyright (c) 1992 Carnegie Mellon University
@ -97,6 +97,8 @@ Tmake(char *p)
{ {
TREE *t; TREE *t;
t = (TREE *) malloc(sizeof(TREE)); t = (TREE *) malloc(sizeof(TREE));
if (t == NULL)
goaway("Cannot allocate memory");
t->Tname = (p == NULL) ? NULL : salloc(p); t->Tname = (p == NULL) ? NULL : salloc(p);
t->Tflags = 0; t->Tflags = 0;
t->Tuid = 0; t->Tuid = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: supcmain.c,v 1.19 2003/01/28 22:35:23 wiz Exp $ */ /* $NetBSD: supcmain.c,v 1.20 2004/12/21 16:20:09 christos Exp $ */
/* /*
* Copyright (c) 1992 Carnegie Mellon University * Copyright (c) 1992 Carnegie Mellon University
@ -672,6 +672,10 @@ init(int argc, char **argv)
mytree->Tcount++; mytree->Tcount++;
} }
c = (COLLECTION *) malloc(sizeof(COLLECTION)); c = (COLLECTION *) malloc(sizeof(COLLECTION));
if (c == NULL) {
logerr("Cannot allocate memory");
exit(1);
}
if (firstC == NULL) if (firstC == NULL)
firstC = c; firstC = c;
if (lastC != NULL) if (lastC != NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: supcmisc.c,v 1.13 2002/07/10 21:28:13 wiz Exp $ */ /* $NetBSD: supcmisc.c,v 1.14 2004/12/21 16:20:09 christos Exp $ */
/* /*
* Copyright (c) 1992 Carnegie Mellon University * Copyright (c) 1992 Carnegie Mellon University
@ -172,6 +172,8 @@ Linsert(LIST ** table, char *name, int number)
int lno; int lno;
lno = Lhash(name); lno = Lhash(name);
l = (LIST *) malloc(sizeof(LIST)); l = (LIST *) malloc(sizeof(LIST));
if (l == NULL)
goaway("Cannot allocate memory");
l->Lname = name; l->Lname = name;
l->Lnumber = number; l->Lnumber = number;
l->Lnext = table[lno]; l->Lnext = table[lno];

View File

@ -1,4 +1,4 @@
/* $NetBSD: supfilesrv.c,v 1.29 2004/04/23 02:58:30 simonb Exp $ */ /* $NetBSD: supfilesrv.c,v 1.30 2004/12/21 16:20:09 christos Exp $ */
/* /*
* Copyright (c) 1992 Carnegie Mellon University * Copyright (c) 1992 Carnegie Mellon University
@ -1536,6 +1536,8 @@ Hinsert(HASH ** table, int num1, int num2, char *name, TREE * tree)
int hno; int hno;
hno = HASHFUNC(num1, num2); hno = HASHFUNC(num1, num2);
h = (HASH *) malloc(sizeof(HASH)); h = (HASH *) malloc(sizeof(HASH));
if (h == NULL)
goaway("Cannot allocate memory");
h->Hnum1 = num1; h->Hnum1 = num1;
h->Hnum2 = num2; h->Hnum2 = num2;
h->Hname = name; h->Hname = name;