Commit ebace696 authored by Sergei Trofimovich's avatar Sergei Trofimovich Committed by Austin Seipp

rts/Capability.c: fix crash in -threaded mode on UNREG build

UNREG mode has quite nasty invariant to maintain:
    capabilities[0] == &MainCapability

and it's a non-heap memory, while other
capabilities are dynamically allocated.

Issue #8748
Signed-off-by: default avatarSergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
parent 4bb50ed0
......@@ -357,15 +357,18 @@ moreCapabilities (nat from USED_IF_THREADS, nat to USED_IF_THREADS)
// BaseReg (eg. unregisterised), so in this case
// capabilities[0] must coincide with &MainCapability.
capabilities[0] = &MainCapability;
initCapability(&MainCapability, 0);
}
for (i = 0; i < to; i++) {
if (i < from) {
capabilities[i] = old_capabilities[i];
} else {
capabilities[i] = stgMallocBytes(sizeof(Capability),
"moreCapabilities");
initCapability(capabilities[i], i);
else
{
for (i = 0; i < to; i++) {
if (i < from) {
capabilities[i] = old_capabilities[i];
} else {
capabilities[i] = stgMallocBytes(sizeof(Capability),
"moreCapabilities");
initCapability(capabilities[i], i);
}
}
}
......@@ -983,7 +986,8 @@ freeCapabilities (void)
nat i;
for (i=0; i < n_capabilities; i++) {
freeCapability(capabilities[i]);
stgFree(capabilities[i]);
if (capabilities[i] != &MainCapability)
stgFree(capabilities[i]);
}
#else
freeCapability(&MainCapability);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment