From 4eaab3fed37d3d09ac7232a646a95cf720369dc9 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 30 Sep 2011 16:17:31 +0400 Subject: [PATCH] tests: Add missing checks of GC_malloc result (for out-of-memory) * tests/test.c (mktree): Insert CHECK_OUT_OF_MEMORY to report mktree() out-of-memory failures. * tests/trace_test.c (mktree): Test whether GC_MALLOC_ATOMIC returns NULL (exit with an error code and the appropriate message printed in this case). --- tests/test.c | 5 ++++- tests/trace_test.c | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test.c b/tests/test.c index 70a05762..6fd8898d 100644 --- a/tests/test.c +++ b/tests/test.c @@ -726,8 +726,11 @@ tn * mktree(int n) result -> lchild = mktree(n-1); result -> rchild = mktree(n-1); if (counter++ % 17 == 0 && n >= 2) { - tn * tmp = result -> lchild -> rchild; + tn * tmp; + CHECK_OUT_OF_MEMORY(result->lchild); + tmp = result -> lchild -> rchild; + CHECK_OUT_OF_MEMORY(result->rchild); result -> lchild -> rchild = result -> rchild -> lchild; result -> rchild -> lchild = tmp; } diff --git a/tests/trace_test.c b/tests/trace_test.c index bb8b813a..923e0f88 100644 --- a/tests/trace_test.c +++ b/tests/trace_test.c @@ -1,4 +1,5 @@ #include +#include #ifndef GC_DEBUG # define GC_DEBUG @@ -16,6 +17,10 @@ struct treenode * mktree(int i) { struct treenode * r = GC_MALLOC(sizeof(struct treenode)); if (0 == i) return 0; if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode)); + if (r == NULL) { + printf("Out of memory\n"); + exit(1); + } r -> x = mktree(i-1); r -> y = mktree(i-1); return r; -- 2.40.0