Bug 1227914: TraceLogger - Limit the memory tracelogger can take, r=bbouvier

This commit is contained in:
Hannes Verschore 2015-11-30 20:45:14 +01:00
parent 8eae746367
commit 83a7889f1f

View File

@ -130,6 +130,9 @@ TLTextIdIsTreeEvent(uint32_t id)
id >= TraceLogger_Last;
}
// The maximum amount of ram memory a continuous space structure can take (in bytes).
static const uint32_t CONTINUOUSSPACE_LIMIT = 200 * 1024 * 1024;
template <class T>
class ContinuousSpace {
T* data_;
@ -194,10 +197,15 @@ class ContinuousSpace {
return true;
uint32_t nCapacity = capacity_ * 2;
if (size_ + count > nCapacity)
if (size_ + count > nCapacity || nCapacity * sizeof(T) > CONTINUOUSSPACE_LIMIT) {
nCapacity = size_ + count;
T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T));
// Limit the size of a continuous buffer.
if (nCapacity * sizeof(T) > CONTINUOUSSPACE_LIMIT)
return false;
}
T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T));
if (!entries)
return false;