| Summary: | Reproducible crash in JavaScriptCore: JSObjectMakeArray() | ||||||
|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Alexander Meißner <AlexanderMeissner> | ||||
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> | ||||
| Status: | RESOLVED INVALID | ||||||
| Severity: | Critical | CC: | adam.fedor, ggaren | ||||
| Priority: | P1 | ||||||
| Version: | 528+ (Nightly build) | ||||||
| Hardware: | Mac (Intel) | ||||||
| OS: | OS X 10.9 | ||||||
| Attachments: |
|
||||||
|
Description
Alexander Meißner
2014-04-15 11:23:41 PDT
Created attachment 229382 [details]
Source code to reproduce the crash
When compiling and running the code, be sure to link against the JavaScriptCore.framework of WebKit Nightly not the one of your system
You can check that by using: otool -L [executable]
Which should show something like:
@executable_path/JavaScriptCore.framework/Versions/A/JavaScriptCore
instead of:
/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore
I reproduced this on my machine (Mid-2011 Mini, OS X 10.10.1) Using Webkit svn rev 176947. I'm interested in this as it seems very similar to a bug I reported to Apple rdar://19378158 (http://openradar.appspot.com/radar?id=6174800997253120) Actually, now I think it might be just an issue with the example. I can't claim to know anything about how JavaScript works, but I think the newly created objects aren't on the stack, so the garbage collector doesn't know about them, so occasionally an object just gets deallocated. Doing something like this fixes the issue: JSValueRef a = newVectorInstance() valueArray[0] = a; ...etc... Does anyone know if that's right or if there is another way to keep an object from being collected? (JSValueProtect/JSValueUnprotect also works, but it seems like that is if you want the objects to be global). (In reply to comment #3) This is actually more the way C/C++ works that matters than the way JavaScript works. The difference is that JSValueRef a = newVectorInstance(); valueArray[0] = a; orders the compiler to use the stack, while valueArray[0] = newVectorInstance(); is a temporary value which could be held in registers. But this is already known to be part of the bug, using the stack is some kind of work around: JSValueRef* valueArray = (JSValueRef*)alloca(sizeof(JSValueRef)*4); I suspect that the problem might be in the Construction/Destruction of JSValue (as that would be stack related) or a memory access in the heap that goes wrong, caused by a early delete/free of memory. > JSValueRef* valueArray = new JSValueRef[8];
It's not valid to put a JSValueRef in the heap without first calling JSValueProtect.
The garbage collector will automatically scan JSValueRefs on the stack, but once you put the JSValueRef into the heap like this, you need to use explicit reference counting through JSValueProtect and JSValueUnprotect.
|