Copy input Buffer to avoid V8 heap compaction #138

This commit is contained in:
Lovell Fuller 2014-12-12 22:02:42 +00:00
parent bd20bd1881
commit 57203f841a

View File

@ -695,6 +695,11 @@ class ResizeWorker : public NanAsyncWorker {
void HandleOKCallback () { void HandleOKCallback () {
NanScope(); NanScope();
// Free input Buffer
if (baton->bufferInLength > 0) {
g_free(baton->bufferIn);
}
Handle<Value> argv[3] = { NanNull(), NanNull(), NanNull() }; Handle<Value> argv[3] = { NanNull(), NanNull(), NanNull() };
if (!baton->err.empty()) { if (!baton->err.empty()) {
// Error // Error
@ -833,8 +838,10 @@ NAN_METHOD(resize) {
// Input Buffer object // Input Buffer object
if (options->Get(NanNew<String>("bufferIn"))->IsObject()) { if (options->Get(NanNew<String>("bufferIn"))->IsObject()) {
Local<Object> buffer = options->Get(NanNew<String>("bufferIn"))->ToObject(); Local<Object> buffer = options->Get(NanNew<String>("bufferIn"))->ToObject();
// Take a copy of the input Buffer to avoid problems with V8 heap compaction
baton->bufferInLength = node::Buffer::Length(buffer); baton->bufferInLength = node::Buffer::Length(buffer);
baton->bufferIn = node::Buffer::Data(buffer); baton->bufferIn = g_malloc(baton->bufferInLength);
memcpy(baton->bufferIn, node::Buffer::Data(buffer), baton->bufferInLength);
} }
// ICC profile to use when input CMYK image has no embedded profile // ICC profile to use when input CMYK image has no embedded profile
baton->iccProfilePath = *String::Utf8Value(options->Get(NanNew<String>("iccProfilePath"))->ToString()); baton->iccProfilePath = *String::Utf8Value(options->Get(NanNew<String>("iccProfilePath"))->ToString());