From 57203f841a2e443c6bf83373121c740be2f6248d Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 12 Dec 2014 22:02:42 +0000 Subject: [PATCH] Copy input Buffer to avoid V8 heap compaction #138 --- src/resize.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/resize.cc b/src/resize.cc index de716f80..0c2a4d92 100755 --- a/src/resize.cc +++ b/src/resize.cc @@ -695,6 +695,11 @@ class ResizeWorker : public NanAsyncWorker { void HandleOKCallback () { NanScope(); + // Free input Buffer + if (baton->bufferInLength > 0) { + g_free(baton->bufferIn); + } + Handle argv[3] = { NanNull(), NanNull(), NanNull() }; if (!baton->err.empty()) { // Error @@ -833,8 +838,10 @@ NAN_METHOD(resize) { // Input Buffer object if (options->Get(NanNew("bufferIn"))->IsObject()) { Local buffer = options->Get(NanNew("bufferIn"))->ToObject(); + // Take a copy of the input Buffer to avoid problems with V8 heap compaction 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 baton->iccProfilePath = *String::Utf8Value(options->Get(NanNew("iccProfilePath"))->ToString());