diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2007-10-24 20:15:44 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2007-10-24 20:15:44 +0000 |
commit | 72cb6bbc56a0543e6f32a45597ab4abcca683082 (patch) | |
tree | abffba762e5ff9f45c24426a3fd22ae59de18f9f | |
parent | f63c595e99b16421792fa149ec178fa67a83f927 (diff) |
add missing checks against NULL after realloc calls
Ok gilles@ moritz@
-rw-r--r-- | usr.bin/vmstat/dkstats.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c index b88eb2e0386..a700747b41e 100644 --- a/usr.bin/vmstat/dkstats.c +++ b/usr.bin/vmstat/dkstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dkstats.c,v 1.31 2007/10/23 07:35:58 chl Exp $ */ +/* $OpenBSD: dkstats.c,v 1.32 2007/10/24 20:15:43 chl Exp $ */ /* $NetBSD: dkstats.c,v 1.1 1996/05/10 23:19:27 thorpej Exp $ */ /* @@ -256,6 +256,15 @@ dkreadstats(void) dk_ndrive * sizeof(*last.dk_wbytes)); last.dk_time = realloc(last.dk_time, dk_ndrive * sizeof(*last.dk_time)); + + if (!cur.dk_select || !cur.dk_rxfer || + !cur.dk_wxfer || !cur.dk_seek || + !cur.dk_rbytes || !cur.dk_wbytes || + !cur.dk_time || !last.dk_rxfer || + !last.dk_wxfer || !last.dk_seek || + !last.dk_rbytes || !last.dk_wbytes || + !last.dk_time) + errx(1, "Memory allocation failure."); } else { cur.dk_select = realloc(cur.dk_select, dk_ndrive * sizeof(*cur.dk_select)); @@ -284,6 +293,15 @@ dkreadstats(void) last.dk_time = realloc(last.dk_time, dk_ndrive * sizeof(*last.dk_time)); + if (!cur.dk_select || !cur.dk_rxfer || + !cur.dk_wxfer || !cur.dk_seek || + !cur.dk_rbytes || !cur.dk_wbytes || + !cur.dk_time || !last.dk_rxfer || + !last.dk_wxfer || !last.dk_seek || + !last.dk_rbytes || !last.dk_wbytes || + !last.dk_time) + errx(1, "Memory allocation failure."); + for (i = dk_ndrive - 1, j = cur.dk_ndrive - 1; i >= 0; i--) { |