Calling new in static initializers causes a crash in Brew MP because Brew MP heap is not yet initialized at this time.
Created attachment 67625 [details] Patch I know this patch is ugly by adding PLATFORM guard. However, if I remove new here, it causes a crash in other ports. See bug 23681 for the reason. Any smart solution here?
I don't understand how this changes things.
(In reply to comment #2) > I don't understand how this changes things. 1) static HashSet<Structure*>& ignoreSet = *(new HashSet<Structure*>); allocates the HashSet memory in the heap. 2) static HashSet<Structure*> ignoreSet; allocates the HashSet memory in the data section. BMP heap is not yet initialized at C++ static initialization time. So it is illegal to call new (which eventually calls Brew MP's MALLOC) in static initializers. 2) never calls MALLOC. So it is okay.
But the project doesn’t allow global initializers anyway, so this should never come up. What’s an example of an object where this happens?
(In reply to comment #4) > But the project doesn’t allow global initializers anyway, so this should never come up. > > What’s an example of an object where this happens? Yes, I know WebKit does not use global initializers. However, there are a few places where global initializers are used to count memory leaks. This happens only in Debug build. For example, in JavaScriptCore/runtime/Structure.cpp static Mutex& ignoreSetMutex = *(new Mutex); static HashSet<Structure*>& ignoreSet = *(new HashSet<Structure*>); static HashSet<Structure*>& liveStructureSet = *(new HashSet<Structure*>); The above three lines call new in global initializers.
I think the better way to solve this problem is to remove the use of global initializers even in Debug build. We can use lazy initialization in memory leak counting and other statistics. I will come up with new patch. Close the bug as "won't fix".