Fix segmentation fault in some Javascript examples
- memory allocated with malloc() was then being freed with delete[], which is overridden by Javascript libraries (jsc), leading to segfault - replacing malloc with %new_array seems to work though
This commit is contained in:
parent
4fe6622f64
commit
6fc07c5dc9
1 changed files with 1 additions and 1 deletions
|
|
@ -8,7 +8,7 @@ SWIG_JSC_AsCharPtrAndSize(JSContextRef context, JSValueRef valRef, char** cptr,
|
|||
if(JSValueIsString(context, valRef)) {
|
||||
JSStringRef js_str = JSValueToStringCopy(context, valRef, NULL);
|
||||
size_t len = JSStringGetMaximumUTF8CStringSize(js_str);
|
||||
char* cstr = (char*) malloc(len * sizeof(char));
|
||||
char* cstr = (char*) %new_array(len, char);
|
||||
/* JSStringGetUTF8CString returns the length including 0-terminator */
|
||||
len = JSStringGetUTF8CString(js_str, cstr, len);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue