From f1752cf299326075a5b83d56cd92380d37717819 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Tue, 23 Feb 2016 12:35:20 +0100 Subject: [PATCH] base_c: fixed codesonar warnings --- base_c/src/thread.c | 5 +++++ base_c/test/alloc_test.cc | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/base_c/src/thread.c b/base_c/src/thread.c index a3963aa..01240db 100644 --- a/base_c/src/thread.c +++ b/base_c/src/thread.c @@ -236,6 +236,11 @@ int embb_thread_create(embb_thread_t* thread, const embb_core_set_t* core_set, /* Dynamic allocation of thread arguments. Freed on call of join. */ thread->embb_internal_arg = (embb_internal_thread_arg_t*) embb_alloc(sizeof(embb_internal_thread_arg_t)); + if (thread->embb_internal_arg == NULL) { + thread->embb_internal_handle = NULL; + pthread_attr_destroy(&attr); + return EMBB_NOMEM; + } thread->embb_internal_arg->func = func; thread->embb_internal_arg->arg = arg; diff --git a/base_c/test/alloc_test.cc b/base_c/test/alloc_test.cc index 3ddaf4a..06ee04b 100644 --- a/base_c/test/alloc_test.cc +++ b/base_c/test/alloc_test.cc @@ -152,6 +152,9 @@ void AllocTest::TestMixedAllocs() { void* plain = NULL; plain = embb_alloc(2); PT_EXPECT_NE(plain, static_cast(NULL)); + if (NULL == plain) { + return; + } allocated = embb_get_bytes_allocated(); #ifdef EMBB_DEBUG expected += 2 + 2*sizeof(size_t); @@ -162,6 +165,10 @@ void AllocTest::TestMixedAllocs() { void* aligned = NULL; aligned = embb_alloc_aligned(2*sizeof(void*), 2); PT_EXPECT_NE(aligned, static_cast(NULL)); + if (NULL == aligned) { + embb_free(plain); + return; + } allocated = embb_get_bytes_allocated(); #ifdef EMBB_DEBUG expected += (1 + 1) * 2 * sizeof(void*) + 3 * sizeof(size_t) - 1; @@ -172,6 +179,11 @@ void AllocTest::TestMixedAllocs() { void* cache_aligned = NULL; cache_aligned = embb_alloc_cache_aligned(2); PT_EXPECT_NE(cache_aligned, static_cast(NULL)); + if (NULL == aligned) { + embb_free(plain); + embb_free_aligned(aligned); + return; + } allocated = embb_get_bytes_allocated(); #ifdef EMBB_DEBUG expected += (1 + 1) * EMBB_PLATFORM_CACHE_LINE_SIZE + 3 * sizeof(size_t) - 1; -- libgit2 0.26.0