Subj : Re: Doing something wrong creating strings for JS function calls To : Brook Monroe From : Brendan Eich Date : Tue Nov 23 2004 03:26 pm Brook Monroe wrote: > var.string = va_arg(ap,char *); > jStr = JS_NewString(cx,var.string,strlen(var.string)); > params[i] = STRING_TO_JSVAL(jStr); > > The app crashes when I destruct the class instance, inside > js32.dll:js_PurgeDeflatedStringCache(). Clearly, the strings I'm > creating aren't done quite correctly...the arguments get where they need > to go, but get tidied up too soon. > > How should I be going about this? Use JS_NewStringCopyN if you don't mean to hand off malloc'ed character storage, which pretty clearly is owned by var in the example cited above, and *not* handed off to the JS engine's deflated string cache. See also JS_NewStringCopyZ, JS_NewUCString, etc. /be .