From a0323a9f8f673f2b4d7a70e2019fa47d3df76d96 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 16 Feb 2011 00:24:49 +0000 Subject: 2011-02-15 Joel Sherrill * libmisc/capture/capture.c, posix/src/keyfreememory.c, posix/src/pthread.c, score/include/rtems/score/wkspace.h, score/src/objectextendinformation.c, score/src/objectnamespaceremove.c, score/src/objectsetname.c, score/src/threadclose.c, score/src/threadinitialize.c, score/src/wkspace.c: Many places were checking for a NULL pointer before calling _Workspace_Free. By moving the check into _Workspace_Free, we eliminate a number of conditional paths and make it harder to return a NULL pointer. --- cpukit/score/include/rtems/score/wkspace.h | 6 ++++-- cpukit/score/src/objectextendinformation.c | 3 +-- cpukit/score/src/objectnamespaceremove.c | 2 +- cpukit/score/src/objectsetname.c | 6 ++---- cpukit/score/src/threadclose.c | 6 ++---- cpukit/score/src/threadinitialize.c | 17 +++++------------ cpukit/score/src/wkspace.c | 5 +++-- 7 files changed, 18 insertions(+), 27 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/include/rtems/score/wkspace.h b/cpukit/score/include/rtems/score/wkspace.h index c29b2dd4c9..c3a0700a01 100644 --- a/cpukit/score/include/rtems/score/wkspace.h +++ b/cpukit/score/include/rtems/score/wkspace.h @@ -70,10 +70,12 @@ void *_Workspace_Allocate( * * @param block is the memory to free * - * @return true if the free was successful. + * @note If @a block is equal to NULL, then the request is ignored. + * This allows the caller to not worry about whether or not + * a pointer is NULL. */ -bool _Workspace_Free( +void _Workspace_Free( void *block ); diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c index ef10e63947..0839e0f6be 100644 --- a/cpukit/score/src/objectextendinformation.c +++ b/cpukit/score/src/objectextendinformation.c @@ -221,8 +221,7 @@ void _Objects_Extend_information( _ISR_Enable( level ); - if ( old_tables ) - _Workspace_Free( old_tables ); + _Workspace_Free( old_tables ); block_count++; } diff --git a/cpukit/score/src/objectnamespaceremove.c b/cpukit/score/src/objectnamespaceremove.c index 5e97a6c34a..d6c0968f90 100644 --- a/cpukit/score/src/objectnamespaceremove.c +++ b/cpukit/score/src/objectnamespaceremove.c @@ -26,7 +26,7 @@ void _Objects_Namespace_remove( /* * If this is a string format name, then free the memory. */ - if ( information->is_string && the_object->name.name_p ) + if ( information->is_string ) _Workspace_Free( (void *)the_object->name.name_p ); #endif diff --git a/cpukit/score/src/objectsetname.c b/cpukit/score/src/objectsetname.c index 3e81811a99..793e0914dd 100644 --- a/cpukit/score/src/objectsetname.c +++ b/cpukit/score/src/objectsetname.c @@ -47,10 +47,8 @@ bool _Objects_Set_name( if ( !d ) return false; - if ( the_object->name.name_p ) { - _Workspace_Free( (void *)the_object->name.name_p ); - the_object->name.name_p = NULL; - } + _Workspace_Free( (void *)the_object->name.name_p ); + the_object->name.name_p = NULL; strncpy( d, name, length ); d[length] = '\0'; diff --git a/cpukit/score/src/threadclose.c b/cpukit/score/src/threadclose.c index aa29ae6a21..2ba29519d9 100644 --- a/cpukit/score/src/threadclose.c +++ b/cpukit/score/src/threadclose.c @@ -101,8 +101,7 @@ void _Thread_Close( #endif the_thread->fp_context = NULL; - if ( the_thread->Start.fp_context ) - (void) _Workspace_Free( the_thread->Start.fp_context ); + _Workspace_Free( the_thread->Start.fp_context ); #endif /* @@ -112,7 +111,6 @@ void _Thread_Close( _Thread_Stack_Free( the_thread ); the_thread->Start.stack = NULL; - if ( the_thread->extensions ) - (void) _Workspace_Free( the_thread->extensions ); + _Workspace_Free( the_thread->extensions ); the_thread->extensions = NULL; } diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index e7aede1cfe..df20017af4 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -225,26 +225,19 @@ bool _Thread_Initialize( return true; failed: - if ( the_thread->libc_reent ) - _Workspace_Free( the_thread->libc_reent ); + _Workspace_Free( the_thread->libc_reent ); for ( i=0 ; i <= THREAD_API_LAST ; i++ ) - if ( the_thread->API_Extensions[i] ) - _Workspace_Free( the_thread->API_Extensions[i] ); + _Workspace_Free( the_thread->API_Extensions[i] ); - if ( extensions_area ) - (void) _Workspace_Free( extensions_area ); + _Workspace_Free( extensions_area ); #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) - if ( fp_area ) - (void) _Workspace_Free( fp_area ); + _Workspace_Free( fp_area ); #endif - if ( sched ) - (void) _Workspace_Free( sched ); + _Workspace_Free( sched ); _Thread_Stack_Free( the_thread ); return false; - - } diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c index 887fa77b45..f8994c2e8d 100644 --- a/cpukit/score/src/wkspace.c +++ b/cpukit/score/src/wkspace.c @@ -79,7 +79,7 @@ void *_Workspace_Allocate( /* * _Workspace_Free */ -bool _Workspace_Free( +void _Workspace_Free( void *block ) { @@ -91,7 +91,8 @@ bool _Workspace_Free( __builtin_return_address( 1 ) ); #endif - return _Heap_Free( &_Workspace_Area, block ); + if (block) + _Heap_Free( &_Workspace_Area, block ); } /* -- cgit v1.2.3