@@ -145,6 +145,9 @@ extern "C" void sysMonitorTimedWait(Word, long long);
145
145
extern "C" void sysMonitorWait (Word );
146
146
extern "C" void sysMonitorBroadcast (Word );
147
147
148
+ static void * checkMalloc (int );
149
+ static void checkFree (void * );
150
+
148
151
// #define DEBUG_SYS
149
152
// #define DEBUG_THREAD
150
153
@@ -1026,7 +1029,7 @@ sysThreadCreate(Address tr, Address ip, Address fp)
1026
1029
1027
1030
// create arguments
1028
1031
//
1029
- sysThreadArguments = new Address [ 3 ] ;
1032
+ sysThreadArguments = ( Address * ) checkMalloc ( sizeof ( Address ) * 3 ) ;
1030
1033
sysThreadArguments [0 ] = tr ;
1031
1034
sysThreadArguments [1 ] = ip ;
1032
1035
sysThreadArguments [2 ] = fp ;
@@ -1134,7 +1137,7 @@ sysThreadStartup(void *args)
1134
1137
char * stackBuf ;
1135
1138
1136
1139
memset (& stack , 0 , sizeof stack );
1137
- stack .ss_sp = stackBuf = new char [ SIGSTKSZ ] ;
1140
+ stack .ss_sp = stackBuf = ( char * ) checkMalloc ( sizeof ( char ) * SIGSTKSZ ) ;
1138
1141
stack .ss_flags = 0 ;
1139
1142
stack .ss_size = SIGSTKSZ ;
1140
1143
if (sigaltstack (& stack , 0 )) {
@@ -1144,18 +1147,18 @@ sysThreadStartup(void *args)
1144
1147
1145
1148
Address tr = ((Address * )args )[0 ];
1146
1149
1147
- jmp_buf * jb = (jmp_buf * )malloc (sizeof (jmp_buf ));
1150
+ jmp_buf * jb = (jmp_buf * )checkMalloc (sizeof (jmp_buf ));
1148
1151
if (setjmp (* jb )) {
1149
1152
// this is where we come to terminate the thread
1150
1153
#ifdef RVM_FOR_HARMONY
1151
1154
hythread_detach (NULL );
1152
1155
#endif
1153
- free (jb );
1156
+ checkFree (jb );
1154
1157
* (int * )(tr + RVMThread_execStatus_offset ) = RVMThread_TERMINATED ;
1155
1158
1156
1159
stack .ss_flags = SS_DISABLE ;
1157
1160
sigaltstack (& stack , 0 );
1158
- delete [] stackBuf ;
1161
+ checkFree ( stackBuf ) ;
1159
1162
} else {
1160
1163
setThreadLocal (TerminateJmpBufKey , (void * )jb );
1161
1164
@@ -1242,7 +1245,7 @@ sysSetupHardwareTrapHandler()
1242
1245
stack_t stack ;
1243
1246
1244
1247
memset (& stack , 0 , sizeof stack );
1245
- stack .ss_sp = new char [ SIGSTKSZ ] ;
1248
+ stack .ss_sp = ( char * ) checkMalloc ( sizeof ( char ) * SIGSTKSZ ) ;
1246
1249
1247
1250
stack .ss_size = SIGSTKSZ ;
1248
1251
if (sigaltstack (& stack , 0 )) {
@@ -1417,7 +1420,7 @@ sysMonitorCreate()
1417
1420
hythread_monitor_t monitor ;
1418
1421
hythread_monitor_init_with_name (& monitor , 0 , NULL );
1419
1422
#else
1420
- vmmonitor_t * monitor = new vmmonitor_t ;
1423
+ vmmonitor_t * monitor = ( vmmonitor_t * ) checkMalloc ( sizeof ( vmmonitor_t )) ;
1421
1424
pthread_mutex_init (& monitor -> mutex , NULL );
1422
1425
pthread_cond_init (& monitor -> cond , NULL );
1423
1426
#endif
@@ -1433,7 +1436,7 @@ sysMonitorDestroy(Word _monitor)
1433
1436
vmmonitor_t * monitor = (vmmonitor_t * )_monitor ;
1434
1437
pthread_mutex_destroy (& monitor -> mutex );
1435
1438
pthread_cond_destroy (& monitor -> cond );
1436
- delete monitor ;
1439
+ checkFree ( monitor ) ;
1437
1440
#endif
1438
1441
}
1439
1442
@@ -1732,10 +1735,8 @@ sysMemmove(void *dst, const void *src, Extent cnt)
1732
1735
1733
1736
int inRVMAddressSpace (Address a );
1734
1737
1735
- // Allocate memory.
1736
- //
1737
- extern "C" void *
1738
- sysMalloc (int length )
1738
+ static void *
1739
+ checkMalloc (int length )
1739
1740
{
1740
1741
void * result = malloc (length );
1741
1742
if (inRVMAddressSpace ((Address )result )) {
@@ -1744,6 +1745,20 @@ sysMalloc(int length)
1744
1745
return result ;
1745
1746
}
1746
1747
1748
+ static void
1749
+ checkFree (void * mem )
1750
+ {
1751
+ free (mem );
1752
+ }
1753
+
1754
+ // Allocate memory.
1755
+ //
1756
+ extern "C" void *
1757
+ sysMalloc (int length )
1758
+ {
1759
+ return checkMalloc (length );
1760
+ }
1761
+
1747
1762
extern "C" void *
1748
1763
sysCalloc (int length )
1749
1764
{
@@ -1755,7 +1770,7 @@ sysCalloc(int length)
1755
1770
extern "C" void
1756
1771
sysFree (void * location )
1757
1772
{
1758
- free (location );
1773
+ checkFree (location );
1759
1774
}
1760
1775
1761
1776
// Zero a range of memory with non-temporal instructions on x86
0 commit comments