From f272c2899a6764eedbe05cea874ee3bd258dbff3 Mon Sep 17 00:00:00 2001 From: "Field G. Van Zee" Date: Wed, 2 Jan 2019 12:34:15 -0600 Subject: [PATCH] Add error message to malloc() check for NULL. Details: - Output an error message if and when the malloc()-equivalent called by bli_fmalloc_align() ever returns NULL. Everything was already in place for this to happen, including the error return code, the error string sprintf(), the error checking function bli_check_valid_malloc_buf() definition, and its prototype. Thanks to Minh Quan Ho for pointing out the missing error message. - Increased the default block_ptrs_len for each inner pool stored in the small block allocator from 10 to 25. Under normal execution, each thread uses only 21 blocks, so this change will prevent the sba from needing to resize the block_ptrs array of any given inner pool as threads initially populate the pool with small blocks upon first execution of a level-3 operation. - Nix stray newline echo in configure. --- configure | 1 - frame/base/bli_apool.c | 2 +- frame/base/bli_malloc.c | 17 +++++++++++++++-- frame/base/bli_malloc.h | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/configure b/configure index ba05cc2c8..093caca03 100755 --- a/configure +++ b/configure @@ -171,7 +171,6 @@ print_usage() echo " it no longer needs to call malloc() or free(), even" echo " across many separate level-3 operation invocations." echo " " - echo " " echo " --enable-mem-tracing, --disable-mem-tracing" echo " " echo " Enable (disable by default) output to stdout that traces" diff --git a/frame/base/bli_apool.c b/frame/base/bli_apool.c index 542c4275a..4a98a090c 100644 --- a/frame/base/bli_apool.c +++ b/frame/base/bli_apool.c @@ -397,7 +397,7 @@ pool_t* bli_apool_array_elem // Settle on the parameters to use when initializing the pool_t for // the current index within the array_t. const siz_t num_blocks = 1; - const siz_t block_ptrs_len = 10; + const siz_t block_ptrs_len = 25; const siz_t align_size = 16; malloc_ft malloc_fp = BLIS_MALLOC_INTL; free_ft free_fp = BLIS_FREE_INTL; diff --git a/frame/base/bli_malloc.c b/frame/base/bli_malloc.c index 4ce5926a2..b6ee6ebd4 100644 --- a/frame/base/bli_malloc.c +++ b/frame/base/bli_malloc.c @@ -155,8 +155,9 @@ void* bli_fmalloc_align // Call the allocation function. p_orig = f( size ); - // If NULL was returned, something is probably very wrong. - if ( p_orig == NULL ) bli_abort(); + // Check the pointer returned by malloc(). + if ( bli_error_checking_is_enabled() ) + bli_fmalloc_align_post_check( p_orig ); // Advance the pointer by one pointer element. p_byte = p_orig; @@ -254,4 +255,16 @@ void bli_fmalloc_align_check bli_check_error_code( e_val ); } +void bli_fmalloc_align_post_check + ( + void* p + ) +{ + err_t e_val; + + // Check for valid values from malloc(). + + e_val = bli_check_valid_malloc_buf( p ); + bli_check_error_code( e_val ); +} diff --git a/frame/base/bli_malloc.h b/frame/base/bli_malloc.h index baa2de048..7945ebdf5 100644 --- a/frame/base/bli_malloc.h +++ b/frame/base/bli_malloc.h @@ -58,4 +58,5 @@ void* bli_fmalloc_noalign( malloc_ft f, size_t size ); void bli_ffree_noalign( free_ft f, void* p ); void bli_fmalloc_align_check( malloc_ft f, size_t size, size_t align_size ); +void bli_fmalloc_align_post_check( void* p );