check malloc() return values

master
orange 12 years ago
parent 562df3ece0
commit 7e2f62da99

@ -104,6 +104,8 @@ int main(int argc, char *argv[]) {
/* Add one element. */ /* Add one element. */
elem_t *one = malloc(sizeof(elem_t)); elem_t *one = malloc(sizeof(elem_t));
if (!one)
dienomem();
one->foo = 23; one->foo = 23;
cb_write(test_cb, one); cb_write(test_cb, one);
free(one); free(one);
@ -111,6 +113,8 @@ int main(int argc, char *argv[]) {
/* Read the one element. */ /* Read the one element. */
elem_t *oneback = malloc(sizeof(elem_t)); elem_t *oneback = malloc(sizeof(elem_t));
if (!oneback)
dienomem();
cb_read(test_cb, oneback); cb_read(test_cb, oneback);
assert(oneback->foo == 23); assert(oneback->foo == 23);
free(oneback); free(oneback);
@ -118,6 +122,8 @@ int main(int argc, char *argv[]) {
/* Fill the buffer. */ /* Fill the buffer. */
elem_t *e = malloc(sizeof(elem_t)); elem_t *e = malloc(sizeof(elem_t));
if (!e)
dienomem();
for (int i = 1; i <= CB_SIZE; i++) { for (int i = 1; i <= CB_SIZE; i++) {
e->foo = i; e->foo = i;
cb_write(test_cb, e); cb_write(test_cb, e);

Loading…
Cancel
Save