{
bdescr *bd;
nat init_sp;
- Capability *cap = &MainCapability;
+ Capability *cap;
+
+ cap = rts_lock();
if (hs_init_count <= 0) {
barf("hs_add_root() must be called after hs_init()");
// ToDo: make this work in the presence of multiple hs_add_root()s.
initProfiling2();
+ rts_unlock(cap);
+
// ditto.
#if defined(THREADED_RTS)
ioManagerStart();
// Originally, this was in report_ccs_profiling(). Now, retainer
// profiling might tack some extra stuff on to the end of this file
// during endProfiling().
- fclose(prof_file);
+ if (prof_file != NULL) fclose(prof_file);
#endif
#if defined(TICKY_TICKY)