[PATCH 2/2] score: Accept NULL pointer in _Freechain_Put()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Jun 30 13:29:36 UTC 2015


With this a _Freechain_Put( _Freechain_Get() ) works always.
---
 cpukit/score/include/rtems/score/freechain.h | 3 ++-
 cpukit/score/src/freechain.c                 | 4 +++-
 testsuites/sptests/spfreechain01/init.c      | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/cpukit/score/include/rtems/score/freechain.h b/cpukit/score/include/rtems/score/freechain.h
index 7fa580a..1540c0e 100644
--- a/cpukit/score/include/rtems/score/freechain.h
+++ b/cpukit/score/include/rtems/score/freechain.h
@@ -93,7 +93,8 @@ void *_Freechain_Get(
  * @brief Puts a node back onto the freechain.
  *
  * @param[in] freechain The freechain control.
- * @param[in] node The node to put back.
+ * @param[in] node The node to put back.  The node may be @c NULL, in this case
+ *   the function does nothing.
  */
 void _Freechain_Put(
   Freechain_Control *freechain,
diff --git a/cpukit/score/src/freechain.c b/cpukit/score/src/freechain.c
index 84b4c63..301e9b2 100644
--- a/cpukit/score/src/freechain.c
+++ b/cpukit/score/src/freechain.c
@@ -74,5 +74,7 @@ void *_Freechain_Get(
 
 void _Freechain_Put( Freechain_Control *freechain, void *node )
 {
-  _Chain_Prepend_unprotected( &freechain->Free, node );
+  if ( node != NULL ) {
+    _Chain_Prepend_unprotected( &freechain->Free, node );
+  }
 }
diff --git a/testsuites/sptests/spfreechain01/init.c b/testsuites/sptests/spfreechain01/init.c
index 8963752..6efcd93 100644
--- a/testsuites/sptests/spfreechain01/init.c
+++ b/testsuites/sptests/spfreechain01/init.c
@@ -40,6 +40,8 @@ static rtems_task Init(rtems_task_argument ignored)
 
     /* check whether freechain put and get works correctly*/
 
+    _Freechain_Put(&fc, NULL);
+
     puts( "INIT - Get node from freechain - OK" );
     node = _Freechain_Get(&fc, malloc, 1, sizeof(test_node));
     node->x = 1;
-- 
1.8.4.5




More information about the devel mailing list