Bug 617505 - Don't OOM so easily growing dense arrays, r=gal

This commit is contained in:
Gregor Wagner 2010-12-08 16:34:38 -08:00
parent 30c5928c9d
commit 6ec4576609
2 changed files with 12 additions and 1 deletions

View File

@ -1656,6 +1656,13 @@ struct JSRuntime {
return JS_LIKELY(!!p) ? p : onOutOfMemory(reinterpret_cast<void *>(1), bytes, cx);
}
void* realloc(void* p, size_t oldBytes, size_t newBytes, JSContext *cx = NULL) {
JS_ASSERT(oldBytes < newBytes);
updateMallocCounter(newBytes - oldBytes);
void *p2 = ::js_realloc(p, newBytes);
return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, newBytes, cx);
}
void* realloc(void* p, size_t bytes, JSContext *cx = NULL) {
/*
* For compatibility we do not account for realloc that increases
@ -2295,6 +2302,10 @@ struct JSContext
return runtime->realloc(p, bytes, this);
}
inline void* realloc(void* p, size_t oldBytes, size_t newBytes) {
return runtime->realloc(p, oldBytes, newBytes, this);
}
inline void free(void* p) {
#ifdef JS_THREADSAFE
if (gcBackgroundFree) {

View File

@ -3939,7 +3939,7 @@ JSObject::growSlots(JSContext *cx, size_t newcap)
if (!hasSlotsArray())
return allocSlots(cx, actualCapacity);
Value *tmpslots = (Value*) cx->realloc(slots, actualCapacity * sizeof(Value));
Value *tmpslots = (Value*) cx->realloc(slots, oldcap * sizeof(Value), actualCapacity * sizeof(Value));
if (!tmpslots)
return false; /* Leave dslots as its old size. */
slots = tmpslots;