summaryrefslogtreecommitdiff
path: root/rts/win32
diff options
context:
space:
mode:
authorGHC GitLab CI <ghc-ci@gitlab-haskell.org>2020-08-21 15:09:18 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-09-05 14:50:52 -0400
commit7980ae23696f2406c65ee498155b26c09d3d4394 (patch)
treeea87c834bafc8167e6c82b3ae11169e92bcd8c09 /rts/win32
parent4813486f8756fde7889b214e6e41ae63465f7ad7 (diff)
downloadhaskell-7980ae23696f2406c65ee498155b26c09d3d4394.tar.gz
rts: Consistently use stgMallocBytes instead of malloc
This can help in debugging RTS memory leaks since all allocations go through the same interface.
Diffstat (limited to 'rts/win32')
-rw-r--r--rts/win32/IOManager.c16
-rw-r--r--rts/win32/OSThreads.c18
-rw-r--r--rts/win32/WorkQueue.c7
3 files changed, 17 insertions, 24 deletions
diff --git a/rts/win32/IOManager.c b/rts/win32/IOManager.c
index 47bcf4bcf4..46bf534114 100644
--- a/rts/win32/IOManager.c
+++ b/rts/win32/IOManager.c
@@ -265,7 +265,7 @@ IOWorkerProc(PVOID param)
}
// Free the WorkItem
DeregisterWorkItem(iom,work);
- free(work);
+ stgFree(work);
} else {
fprintf(stderr, "unable to fetch work; fatal.\n");
fflush(stderr);
@@ -321,7 +321,7 @@ StartIOManager(void)
wq = NewWorkQueue();
if ( !wq ) return false;
- ioMan = (IOManagerState*)malloc(sizeof(IOManagerState));
+ ioMan = (IOManagerState*)stgMallocBytes(sizeof(IOManagerState), "StartIOManager");
if (!ioMan) {
FreeWorkQueue(wq);
@@ -332,7 +332,7 @@ StartIOManager(void)
hExit = CreateEvent ( NULL, true, false, NULL );
if ( !hExit ) {
FreeWorkQueue(wq);
- free(ioMan);
+ stgFree(ioMan);
return false;
}
@@ -440,8 +440,7 @@ AddIORequest ( int fd,
{
ASSERT(ioMan);
- WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
- if (!wItem) return 0;
+ WorkItem* wItem = (WorkItem*)stgMallocBytse(sizeof(WorkItem), "AddIORequest");
unsigned int reqID = ioMan->requestID++;
@@ -471,8 +470,7 @@ AddDelayRequest ( HsInt usecs,
{
ASSERT(ioMan);
- WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
- if (!wItem) return false;
+ WorkItem* wItem = (WorkItem*)stgMallocBytes(sizeof(WorkItem), "AddDelayRequest");
unsigned int reqID = ioMan->requestID++;
@@ -498,7 +496,7 @@ AddProcRequest ( void* proc,
{
ASSERT(ioMan);
- WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
+ WorkItem* wItem = (WorkItem*)stgMallocBytes(sizeof(WorkItem), "AddProcRequest");
if (!wItem) return false;
unsigned int reqID = ioMan->requestID++;
@@ -542,7 +540,7 @@ void ShutdownIOManager ( bool wait_threads )
barf("timeEndPeriod failed");
}
- free(ioMan);
+ stgFree(ioMan);
ioMan = NULL;
}
}
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index 4701c344a0..f3bdefd998 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -171,19 +171,19 @@ void freeThreadingResources (void)
{
if (cpuGroupCache)
{
- free(cpuGroupCache);
+ stgFree(cpuGroupCache);
cpuGroupCache = NULL;
}
if (cpuGroupCumulativeCache)
{
- free(cpuGroupCumulativeCache);
+ stgFree(cpuGroupCumulativeCache);
cpuGroupCumulativeCache = NULL;
}
if (cpuGroupDistCache)
{
- free(cpuGroupDistCache);
+ stgFree(cpuGroupDistCache);
cpuGroupDistCache = NULL;
}
}
@@ -240,7 +240,7 @@ getProcessorsDistribution (void)
if (!cpuGroupDistCache)
{
uint8_t n_groups = getNumberOfProcessorsGroups();
- cpuGroupDistCache = malloc(n_groups * sizeof(uint8_t));
+ cpuGroupDistCache = stgMallocBytes(n_groups * sizeof(uint8_t), "getProcessorsDistribution");
memset(cpuGroupDistCache, MAXIMUM_PROCESSORS, n_groups * sizeof(uint8_t));
for (int i = 0; i < n_groups; i++)
@@ -265,7 +265,7 @@ getProcessorsCumulativeSum(void)
if (!cpuGroupCumulativeCache)
{
uint8_t n_groups = getNumberOfProcessorsGroups();
- cpuGroupCumulativeCache = malloc(n_groups * sizeof(uint32_t));
+ cpuGroupCumulativeCache = stgMallocBytes(n_groups * sizeof(uint32_t), "getProcessorsCumulativeSum");
memset(cpuGroupCumulativeCache, 0, n_groups * sizeof(uint32_t));
#if defined(x86_64_HOST_ARCH)
@@ -306,7 +306,7 @@ createProcessorGroupMap (void)
uint32_t numProcs = getNumberOfProcessors();
- cpuGroupCache = malloc(numProcs * sizeof(uint8_t));
+ cpuGroupCache = stgMallocBytes(numProcs * sizeof(uint8_t), "createProcessorGroupMap");
/* For 32bit Windows and 64bit older than Windows 7, create a default mapping. */
memset(cpuGroupCache, 0, numProcs * sizeof(uint8_t));
@@ -386,7 +386,7 @@ setThreadAffinity (uint32_t n, uint32_t m) // cap N of M
ASSERT(n_groups > 0);
ASSERT(n_proc > 0);
- mask = malloc(n_groups * sizeof(DWORD_PTR));
+ mask = stgMallocBytes(n_groups * sizeof(DWORD_PTR), "setThreadAffinity");
memset(mask, 0, n_groups * sizeof(DWORD_PTR));
/* The mask for the individual groups are all 0 based
@@ -422,14 +422,14 @@ setThreadAffinity (uint32_t n, uint32_t m) // cap N of M
{
r = SetThreadAffinityMask(hThread, mask[i]);
if (r == 0) {
- free(mask);
+ stgFree(mask);
sysErrorBelch("SetThreadAffinity");
stg_exit(EXIT_FAILURE);
}
}
}
- free(mask);
+ stgFree(mask);
}
void
diff --git a/rts/win32/WorkQueue.c b/rts/win32/WorkQueue.c
index dba20c668b..e89092f122 100644
--- a/rts/win32/WorkQueue.c
+++ b/rts/win32/WorkQueue.c
@@ -41,12 +41,7 @@ newSemaphore(int initCount, int max)
WorkQueue*
NewWorkQueue()
{
- WorkQueue* wq = (WorkQueue*)malloc(sizeof(WorkQueue));
-
- if (!wq) {
- queue_error("NewWorkQueue", "malloc() failed");
- return wq;
- }
+ WorkQueue* wq = (WorkQueue*)stgMallocBytes(sizeof(WorkQueue), "NewWorkQueue");
memset(wq, 0, sizeof *wq);