From 7e2f62da996b5012dc48a5b6d178a56e676e8066 Mon Sep 17 00:00:00 2001 From: orange Date: Sun, 30 Jun 2013 22:10:52 +0200 Subject: [PATCH] check malloc() return values --- circular-buffer.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/circular-buffer.c b/circular-buffer.c index b79db30..99fe89f 100644 --- a/circular-buffer.c +++ b/circular-buffer.c @@ -104,6 +104,8 @@ int main(int argc, char *argv[]) { /* Add one element. */ elem_t *one = malloc(sizeof(elem_t)); + if (!one) + dienomem(); one->foo = 23; cb_write(test_cb, one); free(one); @@ -111,6 +113,8 @@ int main(int argc, char *argv[]) { /* Read the one element. */ elem_t *oneback = malloc(sizeof(elem_t)); + if (!oneback) + dienomem(); cb_read(test_cb, oneback); assert(oneback->foo == 23); free(oneback); @@ -118,6 +122,8 @@ int main(int argc, char *argv[]) { /* Fill the buffer. */ elem_t *e = malloc(sizeof(elem_t)); + if (!e) + dienomem(); for (int i = 1; i <= CB_SIZE; i++) { e->foo = i; cb_write(test_cb, e);