@@ -24,10 +24,8 @@ freely, subject to the following restrictions:
24
24
SPDX-License-Identifier: Zlib
25
25
*/
26
26
27
+ #include "raii.h"
27
28
#ifndef HAS_C11_THREADS
28
- #include "cthread.h"
29
- #include <stdlib.h>
30
-
31
29
/* Platform specific includes */
32
30
#if defined(_TTHREAD_POSIX_ )
33
31
#include <signal.h>
@@ -581,7 +579,7 @@ static void * _thrd_wrapper_function(void * aArg)
581
579
arg = ti -> mArg ;
582
580
583
581
/* The thread is responsible for freeing the startup information */
584
- free ((void * )ti );
582
+ RAII_FREE ((void * )ti );
585
583
586
584
/* Call the actual client thread function */
587
585
res = fun (arg );
@@ -671,7 +669,7 @@ static void _remove_thread_data(DWORD thread_id)
671
669
if (node -> thread_id == thread_id )
672
670
{
673
671
_cthread_thread_head = node -> next ;
674
- free (node );
672
+ RAII_FREE (node );
675
673
ReleaseSRWLockExclusive (& _cthread_thread_head_srwlock );
676
674
return ;
677
675
}
@@ -681,7 +679,7 @@ static void _remove_thread_data(DWORD thread_id)
681
679
{
682
680
struct CThreadThrdData * needle = node -> next ;
683
681
node -> next = needle -> next ;
684
- free (needle );
682
+ RAII_FREE (needle );
685
683
ReleaseSRWLockExclusive (& _cthread_thread_head_srwlock );
686
684
return ;
687
685
}
@@ -696,7 +694,7 @@ int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
696
694
{
697
695
/* Fill out the thread startup information (passed to the thread wrapper,
698
696
which will eventually free it) */
699
- _thread_start_info * ti = (_thread_start_info * )malloc (sizeof (_thread_start_info ));
697
+ _thread_start_info * ti = (_thread_start_info * )RAII_MALLOC (sizeof (_thread_start_info ));
700
698
if (ti == NULL )
701
699
{
702
700
return thrd_nomem ;
@@ -707,17 +705,17 @@ int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
707
705
/* Create the thread */
708
706
#if defined(_TTHREAD_WIN32_ )
709
707
struct CThreadThrdData * data ;
710
- data = (struct CThreadThrdData * )malloc (sizeof (struct CThreadThrdData ));
708
+ data = (struct CThreadThrdData * )RAII_MALLOC (sizeof (struct CThreadThrdData ));
711
709
if (data == NULL )
712
710
{
713
- free (ti );
711
+ RAII_FREE (ti );
714
712
return thrd_nomem ;
715
713
}
716
714
HANDLE handle = CreateThread (NULL , 0 , _thrd_wrapper_function , (LPVOID )ti , 0 , NULL );
717
715
if (handle == NULL )
718
716
{
719
- free (ti );
720
- free (data );
717
+ RAII_FREE (ti );
718
+ RAII_FREE (data );
721
719
return thrd_error ;
722
720
}
723
721
data -> handle = handle ;
@@ -728,7 +726,7 @@ int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
728
726
#elif defined(_TTHREAD_POSIX_ )
729
727
if (pthread_create (thr , NULL , _thrd_wrapper_function , (void * )ti ) != 0 )
730
728
{
731
- free (ti );
729
+ RAII_FREE (ti );
732
730
return thrd_error ;
733
731
}
734
732
#endif
@@ -965,7 +963,7 @@ int tss_set(tss_t key, void *val)
965
963
struct CThreadTSSData * data = (struct CThreadTSSData * )TlsGetValue (key );
966
964
if (data == NULL )
967
965
{
968
- data = (struct CThreadTSSData * )malloc (sizeof (struct CThreadTSSData ));
966
+ data = (struct CThreadTSSData * )RAII_MALLOC (sizeof (struct CThreadTSSData ));
969
967
if (data == NULL )
970
968
{
971
969
return thrd_error ;
0 commit comments