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:
Karl Wette 2014-05-02 01:28:15 +02:00
commit 6fc07c5dc9

View file

@ -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);