summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthreadcreate.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-02-25 19:08:52 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-02-26 09:23:02 +0100
commit1ac4a85ebf0cd0e788c2d5374c635087c33de0bf (patch)
tree55e5da6a482cc00eb616c6d01b9f2732900ab2b4 /cpukit/posix/src/pthreadcreate.c
parentlibtest: Print SHA256 hash in base64url (diff)
downloadrtems-1ac4a85ebf0cd0e788c2d5374c635087c33de0bf.tar.bz2
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.
Diffstat (limited to 'cpukit/posix/src/pthreadcreate.c')
-rw-r--r--cpukit/posix/src/pthreadcreate.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 33c5f8d03a..55ba73c8b4 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -26,6 +26,7 @@
#include <pthread.h>
#include <errno.h>
+#include <rtems/posix/posixapi.h>
#include <rtems/posix/priorityimpl.h>
#if defined(RTEMS_POSIX_API)
#include <rtems/posix/psignalimpl.h>
@@ -72,7 +73,8 @@ int pthread_create(
int normal_prio;
bool valid;
Thread_Configuration config;
- bool status;
+ Status_Control status;
+ bool ok;
Thread_Control *the_thread;
Thread_Control *executing;
int schedpolicy = SCHED_RR;
@@ -224,22 +226,23 @@ int pthread_create(
config.stack_free = _Stack_Free_nothing;
}
- status = ( config.stack_area != NULL );
+ if ( config.stack_area == NULL ) {
+ _Objects_Free( &_POSIX_Threads_Information.Objects, &the_thread->Object );
+ _Objects_Allocator_unlock();
+ return EAGAIN;
+ }
/*
* Initialize the core thread for this task.
*/
- if ( status ) {
- status = _Thread_Initialize(
- &_POSIX_Threads_Information,
- the_thread,
- &config
- );
- }
- if ( !status ) {
- _POSIX_Threads_Free( the_thread );
+ status = _Thread_Initialize(
+ &_POSIX_Threads_Information,
+ the_thread,
+ &config
+ );
+ if ( status != STATUS_SUCCESSFUL ) {
_Objects_Allocator_unlock();
- return EAGAIN;
+ return _POSIX_Get_error( status );
}
if ( the_attr->detachstate == PTHREAD_CREATE_DETACHED ) {
@@ -249,14 +252,14 @@ int pthread_create(
the_thread->Life.state |= THREAD_LIFE_CHANGE_DEFERRED;
_ISR_lock_ISR_disable( &lock_context );
- status = _Scheduler_Set_affinity(
+ ok = _Scheduler_Set_affinity(
the_thread,
the_attr->affinitysetsize,
the_attr->affinityset
);
_ISR_lock_ISR_enable( &lock_context );
- if ( !status ) {
- _POSIX_Threads_Free( the_thread );
+ if ( !ok ) {
+ _Thread_Free( &_POSIX_Threads_Information, the_thread );
_RTEMS_Unlock_allocator();
return EINVAL;
}
@@ -287,7 +290,7 @@ int pthread_create(
* POSIX threads are allocated and started in one operation.
*/
_ISR_lock_ISR_disable( &lock_context );
- status = _Thread_Start( the_thread, &entry, &lock_context );
+ ok = _Thread_Start( the_thread, &entry, &lock_context );
#if defined(RTEMS_DEBUG)
/*
@@ -296,8 +299,8 @@ int pthread_create(
* NOTE: This can only happen if someone slips in and touches the
* thread while we are creating it.
*/
- if ( !status ) {
- _POSIX_Threads_Free( the_thread );
+ if ( !ok ) {
+ _Thread_Free( &_POSIX_Threads_Information, the_thread );
_Objects_Allocator_unlock();
return EINVAL;
}