From: Ivan Maidanski Date: Tue, 9 Feb 2016 20:35:33 +0000 (+0300) Subject: Fix null pointer dereference on out-of-memory in tests X-Git-Tag: gc7_4_4~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86390921d7e69a708f2cfc8ae687c2aced1dcd1b;p=gc Fix null pointer dereference on out-of-memory in tests (Apply commit 9c6d1b3 from 'master' branch.) * tests/disclaim_bench.c (main): Check GC_MALLOC result for NULL (abort in case of out-of-memory) before dereference. * tests/test.c (run_one_test): Likewise. --- diff --git a/tests/disclaim_bench.c b/tests/disclaim_bench.c index 5159829c..cf31a4a5 100644 --- a/tests/disclaim_bench.c +++ b/tests/disclaim_bench.c @@ -91,9 +91,6 @@ int main(int argc, char **argv) GC_INIT(); GC_init_finalized_malloc(); - - keep_arr = GC_MALLOC(sizeof(void *)*KEEP_CNT); - if (argc == 2 && strcmp(argv[1], "--help") == 0) { fprintf(stderr, "Usage: %s [FINALIZATION_MODEL]\n" @@ -112,6 +109,12 @@ int main(int argc, char **argv) model_max = 2; } + keep_arr = GC_MALLOC(sizeof(void *) * KEEP_CNT); + if (NULL == keep_arr) { + fprintf(stderr, "Out of memory!\n"); + exit(3); + } + printf("\t\t\tfin. ratio time/s time/fin.\n"); for (model = model_min; model <= model_max; ++model) { double t = 0.0; diff --git a/tests/test.c b/tests/test.c index 9f3afa4a..4c1cc7fc 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1222,6 +1222,7 @@ void run_one_test(void) FAIL; } z = GC_malloc(8); + CHECK_OUT_OF_MEMORY(z); GC_PTR_STORE(z, x); if (*z != x) { GC_printf("GC_PTR_STORE failed: %p != %p\n", (void *)(*z), (void *)x);