From 1ac4a85ebf0cd0e788c2d5374c635087c33de0bf Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 25 Feb 2021 19:08:52 +0100 Subject: score: Fix thread initialization Close the thread object if a thread create extension fails. Also call the delete extension to avoid resource leaks in early extensions if a late extension fails. Close #4270. --- cpukit/rtems/src/taskconstruct.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'cpukit/rtems/src/taskconstruct.c') diff --git a/cpukit/rtems/src/taskconstruct.c b/cpukit/rtems/src/taskconstruct.c index 799554c417..397f6c2c89 100644 --- a/cpukit/rtems/src/taskconstruct.c +++ b/cpukit/rtems/src/taskconstruct.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -79,14 +80,6 @@ rtems_status_code rtems_task_construct( return _RTEMS_tasks_Create( config, id, _RTEMS_tasks_Prepare_user_stack ); } -static void _RTEMS_tasks_Free( Thread_Control *the_thread ) -{ - Thread_Information *information; - - information = _Thread_Get_objects_information( the_thread ); - _Objects_Free( &information->Objects, &the_thread->Object ); -} - rtems_status_code _RTEMS_tasks_Create( const rtems_task_config *config, rtems_id *id, @@ -190,7 +183,7 @@ rtems_status_code _RTEMS_tasks_Create( the_global_object = _Objects_MP_Allocate_global_object(); if ( the_global_object == NULL ) { - _RTEMS_tasks_Free( the_thread ); + _Objects_Free( &_RTEMS_tasks_Information.Objects, &the_thread->Object ); _Objects_Allocator_unlock(); return RTEMS_TOO_MANY; } @@ -204,17 +197,16 @@ rtems_status_code _RTEMS_tasks_Create( */ if ( status == RTEMS_SUCCESSFUL ) { - bool ok; + Status_Control score_status; - ok = _Thread_Initialize( + score_status = _Thread_Initialize( &_RTEMS_tasks_Information, the_thread, &thread_config ); - - if ( !ok ) { - status = RTEMS_UNSATISFIED; - } + status = _Status_Get( score_status ); + } else { + _Objects_Free( &_RTEMS_tasks_Information.Objects, &the_thread->Object ); } if ( status != RTEMS_SUCCESSFUL ) { @@ -222,7 +214,6 @@ rtems_status_code _RTEMS_tasks_Create( if ( is_global ) _Objects_MP_Free_global_object( the_global_object ); #endif - _RTEMS_tasks_Free( the_thread ); _Objects_Allocator_unlock(); return status; } -- cgit v1.2.3