summaryrefslogtreecommitdiff
path: root/rts/Capability.c
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2014-02-13 07:26:05 -0600
committerAustin Seipp <austin@well-typed.com>2014-02-17 01:46:03 -0600
commitebace6969f0ec85b1caa0fea265a5f9990a23b2e (patch)
treec7545d03cb7bfb911855f6d23cdc89d2a4e05783 /rts/Capability.c
parent4bb50ed0c6246e2d45e22e79f5658db1fa8a58b3 (diff)
downloadhaskell-ebace6969f0ec85b1caa0fea265a5f9990a23b2e.tar.gz
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: Sergei Trofimovich <slyfox@gentoo.org> Signed-off-by: Austin Seipp <austin@well-typed.com>
Diffstat (limited to 'rts/Capability.c')
-rw-r--r--rts/Capability.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/rts/Capability.c b/rts/Capability.c
index 5988d4205c..16b71b7045 100644
--- a/rts/Capability.c
+++ b/rts/Capability.c
@@ -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);