WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
45794
[BREWMP] Don't use new in static initializers
https://bugs.webkit.org/show_bug.cgi?id=45794
Summary
[BREWMP] Don't use new in static initializers
Kwang Yul Seo
Reported
2010-09-14 17:38:47 PDT
Calling new in static initializers causes a crash in Brew MP because Brew MP heap is not yet initialized at this time.
Attachments
Patch
(1.59 KB, patch)
2010-09-14 17:43 PDT
,
Kwang Yul Seo
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Kwang Yul Seo
Comment 1
2010-09-14 17:43:57 PDT
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?
Eric Seidel (no email)
Comment 2
2010-09-14 23:49:24 PDT
I don't understand how this changes things.
Kwang Yul Seo
Comment 3
2010-09-15 00:06:24 PDT
(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.
Darin Adler
Comment 4
2010-09-15 10:10:56 PDT
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?
Kwang Yul Seo
Comment 5
2010-09-15 10:24:46 PDT
(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.
Kwang Yul Seo
Comment 6
2010-09-17 15:46:20 PDT
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".
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug