Bug 1166041 - Fix memory leaked by nursery when we hit OOM r=terrence

This commit is contained in:
Jon Coppeard 2015-05-29 10:46:27 +01:00
parent b38fcaf496
commit 885ad20f3a

View File

@ -246,9 +246,9 @@ js::Nursery::allocateBuffer(Zone* zone, uint32_t nbytes)
}
void* buffer = zone->pod_malloc<uint8_t>(nbytes);
if (buffer) {
/* If this put fails, we will only leak the slots. */
(void)mallocedBuffers.put(buffer);
if (buffer && !mallocedBuffers.putNew(buffer)) {
js_free(buffer);
return nullptr;
}
return buffer;
}
@ -273,11 +273,8 @@ js::Nursery::reallocateBuffer(JSObject* obj, void* oldBuffer,
if (!isInside(oldBuffer)) {
void* newBuffer = obj->zone()->pod_realloc<uint8_t>((uint8_t*)oldBuffer, oldBytes, newBytes);
if (newBuffer && oldBytes != newBytes) {
removeMallocedBuffer(oldBuffer);
/* If this put fails, we will only leak the slots. */
(void)mallocedBuffers.put(newBuffer);
}
if (newBuffer && oldBuffer != newBuffer)
MOZ_ALWAYS_TRUE(mallocedBuffers.rekeyAs(oldBuffer, newBuffer, newBuffer));
return newBuffer;
}