From 03cbcf11496cabf964f94845e7bbbfe368400fb9 Mon Sep 17 00:00:00 2001 From: christos Date: Tue, 21 Dec 2004 16:20:09 +0000 Subject: [PATCH] check error return from malloc and bail. --- usr.sbin/sup/source/stree.c | 4 +++- usr.sbin/sup/source/supcmain.c | 6 +++++- usr.sbin/sup/source/supcmisc.c | 4 +++- usr.sbin/sup/source/supfilesrv.c | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/usr.sbin/sup/source/stree.c b/usr.sbin/sup/source/stree.c index a42093385ca6..f9508bc6f4de 100644 --- a/usr.sbin/sup/source/stree.c +++ b/usr.sbin/sup/source/stree.c @@ -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 @@ -97,6 +97,8 @@ Tmake(char *p) { TREE *t; t = (TREE *) malloc(sizeof(TREE)); + if (t == NULL) + goaway("Cannot allocate memory"); t->Tname = (p == NULL) ? NULL : salloc(p); t->Tflags = 0; t->Tuid = 0; diff --git a/usr.sbin/sup/source/supcmain.c b/usr.sbin/sup/source/supcmain.c index 60a74f4d1692..29b0973bbac9 100644 --- a/usr.sbin/sup/source/supcmain.c +++ b/usr.sbin/sup/source/supcmain.c @@ -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 @@ -672,6 +672,10 @@ init(int argc, char **argv) mytree->Tcount++; } c = (COLLECTION *) malloc(sizeof(COLLECTION)); + if (c == NULL) { + logerr("Cannot allocate memory"); + exit(1); + } if (firstC == NULL) firstC = c; if (lastC != NULL) diff --git a/usr.sbin/sup/source/supcmisc.c b/usr.sbin/sup/source/supcmisc.c index 32d6c3cf9697..e2b67bdb4388 100644 --- a/usr.sbin/sup/source/supcmisc.c +++ b/usr.sbin/sup/source/supcmisc.c @@ -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 @@ -172,6 +172,8 @@ Linsert(LIST ** table, char *name, int number) int lno; lno = Lhash(name); l = (LIST *) malloc(sizeof(LIST)); + if (l == NULL) + goaway("Cannot allocate memory"); l->Lname = name; l->Lnumber = number; l->Lnext = table[lno]; diff --git a/usr.sbin/sup/source/supfilesrv.c b/usr.sbin/sup/source/supfilesrv.c index e204a1ec9aba..11293e283cab 100644 --- a/usr.sbin/sup/source/supfilesrv.c +++ b/usr.sbin/sup/source/supfilesrv.c @@ -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 @@ -1536,6 +1536,8 @@ Hinsert(HASH ** table, int num1, int num2, char *name, TREE * tree) int hno; hno = HASHFUNC(num1, num2); h = (HASH *) malloc(sizeof(HASH)); + if (h == NULL) + goaway("Cannot allocate memory"); h->Hnum1 = num1; h->Hnum2 = num2; h->Hname = name;