Browse Source

smalloc: zero size allocs may need to be free'd

Zero size allocations don't necessarily mean that data == NULL. So
instead check each value seperately and perform necessary operations.
Trevor Norris 12 years ago
parent
commit
aa8c4a0766
  1. 17
      src/smalloc.cc

17
src/smalloc.cc

@ -180,14 +180,15 @@ void AllocDispose(Handle<Object> obj) {
char* data = static_cast<char*>(obj->GetIndexedPropertiesExternalArrayData());
size_t length = obj->GetIndexedPropertiesExternalArrayDataLength();
if (data == NULL || length == 0)
return;
obj->SetIndexedPropertiesToExternalArrayData(NULL,
kExternalUnsignedByteArray,
0);
free(data);
node_isolate->AdjustAmountOfExternalAllocatedMemory(-length);
if (data != NULL) {
obj->SetIndexedPropertiesToExternalArrayData(NULL,
kExternalUnsignedByteArray,
0);
free(data);
}
if (length != 0) {
node_isolate->AdjustAmountOfExternalAllocatedMemory(-length);
}
}

Loading…
Cancel
Save