Protect js_GetStringBytes from callers that happen during the last GC. Patch from brendan, bug 336907, r=daumling sr=shaver

This commit is contained in:
mrbkap%gmail.com 2007-06-18 21:38:31 +00:00
Родитель aba6d7eb3b
Коммит e94ecb5e66
1 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -2924,7 +2924,7 @@ js_DeflateStringToBuffer(JSContext *cx, const jschar *src, size_t srclen,
}
if (v < 0x0080) {
/* no encoding necessary - performance hack */
if (!dstlen)
if (dstlen == 0)
goto bufferTooSmall;
*dst++ = (char) v;
utf8Len = 1;
@ -3038,7 +3038,7 @@ bufferTooSmall:
return JS_FALSE;
}
#else
#else /* !JS_C_STRINGS_ARE_UTF8 */
JSBool
js_InflateStringToBuffer(JSContext* cx, const char *bytes, size_t length,
@ -3192,6 +3192,15 @@ js_GetStringBytes(JSContext *cx, JSString *str)
rt = js_GetGCStringRuntime(str);
}
if (!rt->deflatedStringCache) {
/*
* Called from last GC (see js_DestroyContext), after runtime string
* state has been finalized. We have no choice but to leak here.
*/
return js_DeflateString(NULL, JSSTRING_CHARS(str),
JSSTRING_LENGTH(str));
}
JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);
cache = GetDeflatedStringCache(rt);