[rtems commit] posix: Fix POSIX keys initialization

Sebastian Huber sebh at rtems.org
Tue May 6 11:40:22 UTC 2014


Module:    rtems
Branch:    master
Commit:    7d1436e4b3d56062fa602d14430265807430a116
Changeset: http://git.rtems.org/rtems/commit/?id=7d1436e4b3d56062fa602d14430265807430a116

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue May  6 13:41:28 2014 +0200

posix: Fix POSIX keys initialization

Always initialize the freechain.  This prevents a NULL pointer access in
case no initial key value pairs are defined.

---

 cpukit/posix/src/key.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c
index 10fc3e9..de61b43 100644
--- a/cpukit/posix/src/key.c
+++ b/cpukit/posix/src/key.c
@@ -112,16 +112,16 @@ static bool _POSIX_Keys_Keypool_extend( Freechain_Control *keypool )
 
 static void _POSIX_Keys_Initialize_keypool( void )
 {
+  Freechain_Control *keypool = &_POSIX_Keys_Keypool;
   size_t initial_count = _POSIX_Keys_Get_initial_keypool_size();
-  size_t size = initial_count * sizeof( POSIX_Keys_Key_value_pair );
 
-  if ( size > 0 ) {
-    Freechain_Control *keypool = &_POSIX_Keys_Keypool;
+  _Freechain_Initialize( keypool, _POSIX_Keys_Keypool_extend );
+
+  if ( initial_count > 0 ) {
+    size_t size = initial_count * sizeof( POSIX_Keys_Key_value_pair );
     POSIX_Keys_Key_value_pair *nodes =
       _Workspace_Allocate_or_fatal_error( size );
 
-    _Freechain_Initialize( keypool, _POSIX_Keys_Keypool_extend );
-
     _Chain_Initialize(
       &keypool->Freechain,
       nodes,




More information about the vc mailing list