mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Remove optional AdjustAmountOfExternalAllocatedMemory #151
Isolate not available when deleting the buffer
This commit is contained in:
parent
855945bef2
commit
fe34548bad
@ -34,7 +34,7 @@
|
|||||||
"vips"
|
"vips"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bluebird": "^2.6.4",
|
"bluebird": "^2.8.2",
|
||||||
"color": "^0.7.3",
|
"color": "^0.7.3",
|
||||||
"nan": "^1.5.1",
|
"nan": "^1.5.1",
|
||||||
"semver": "^4.2.0"
|
"semver": "^4.2.0"
|
||||||
|
@ -129,14 +129,10 @@ struct ResizeBaton {
|
|||||||
Delete input char[] buffer and notify V8 of memory deallocation
|
Delete input char[] buffer and notify V8 of memory deallocation
|
||||||
Used as the callback function for the "postclose" signal
|
Used as the callback function for the "postclose" signal
|
||||||
*/
|
*/
|
||||||
static void DeleteBuffer(VipsObject *object, std::tuple<char*, size_t> *buffer) {
|
static void DeleteBuffer(VipsObject *object, char *buffer) {
|
||||||
char* data = std::get<0>(*buffer);
|
if (buffer != NULL) {
|
||||||
size_t length = std::get<1>(*buffer);
|
delete[] buffer;
|
||||||
if (data != NULL) {
|
|
||||||
delete[] data;
|
|
||||||
}
|
}
|
||||||
NanAdjustExternalMemory(static_cast<int>(-length));
|
|
||||||
delete buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ResizeWorker : public NanAsyncWorker {
|
class ResizeWorker : public NanAsyncWorker {
|
||||||
@ -167,21 +163,20 @@ class ResizeWorker : public NanAsyncWorker {
|
|||||||
if (baton->bufferInLength > 1) {
|
if (baton->bufferInLength > 1) {
|
||||||
// From buffer
|
// From buffer
|
||||||
inputImageType = DetermineImageType(baton->bufferIn, baton->bufferInLength);
|
inputImageType = DetermineImageType(baton->bufferIn, baton->bufferInLength);
|
||||||
std::tuple<char*, size_t> *buffer = new std::tuple<char*, size_t>(baton->bufferIn, baton->bufferInLength);
|
|
||||||
if (inputImageType != ImageType::UNKNOWN) {
|
if (inputImageType != ImageType::UNKNOWN) {
|
||||||
image = InitImage(inputImageType, baton->bufferIn, baton->bufferInLength, baton->accessMethod);
|
image = InitImage(inputImageType, baton->bufferIn, baton->bufferInLength, baton->accessMethod);
|
||||||
if (image != NULL) {
|
if (image != NULL) {
|
||||||
// Listen for "postclose" signal to delete input buffer
|
// Listen for "postclose" signal to delete input buffer
|
||||||
g_signal_connect(image, "postclose", G_CALLBACK(DeleteBuffer), buffer);
|
g_signal_connect(image, "postclose", G_CALLBACK(DeleteBuffer), baton->bufferIn);
|
||||||
} else {
|
} else {
|
||||||
// Could not read header data
|
// Could not read header data
|
||||||
(baton->err).append("Input buffer has corrupt header");
|
(baton->err).append("Input buffer has corrupt header");
|
||||||
inputImageType = ImageType::UNKNOWN;
|
inputImageType = ImageType::UNKNOWN;
|
||||||
DeleteBuffer(NULL, buffer);
|
DeleteBuffer(NULL, baton->bufferIn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(baton->err).append("Input buffer contains unsupported image format");
|
(baton->err).append("Input buffer contains unsupported image format");
|
||||||
DeleteBuffer(NULL, buffer);
|
DeleteBuffer(NULL, baton->bufferIn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// From file
|
// From file
|
||||||
@ -820,7 +815,7 @@ class ResizeWorker : public NanAsyncWorker {
|
|||||||
if (baton->bufferOutLength > 0) {
|
if (baton->bufferOutLength > 0) {
|
||||||
// Copy data to new Buffer
|
// Copy data to new Buffer
|
||||||
argv[1] = NanNewBufferHandle(static_cast<char*>(baton->bufferOut), baton->bufferOutLength);
|
argv[1] = NanNewBufferHandle(static_cast<char*>(baton->bufferOut), baton->bufferOutLength);
|
||||||
// bufferOut was allocated via malloc
|
// bufferOut was allocated via g_malloc
|
||||||
g_free(baton->bufferOut);
|
g_free(baton->bufferOut);
|
||||||
// Add buffer size to info
|
// Add buffer size to info
|
||||||
info->Set(NanNew<String>("size"), NanNew<Uint32>(static_cast<uint32_t>(baton->bufferOutLength)));
|
info->Set(NanNew<String>("size"), NanNew<Uint32>(static_cast<uint32_t>(baton->bufferOutLength)));
|
||||||
@ -945,8 +940,6 @@ NAN_METHOD(resize) {
|
|||||||
baton->bufferIn = new char[baton->bufferInLength];
|
baton->bufferIn = new char[baton->bufferInLength];
|
||||||
memcpy(baton->bufferIn, node::Buffer::Data(buffer), baton->bufferInLength);
|
memcpy(baton->bufferIn, node::Buffer::Data(buffer), baton->bufferInLength);
|
||||||
options->Set(NanNew<String>("bufferIn"), NanNull());
|
options->Set(NanNew<String>("bufferIn"), NanNull());
|
||||||
// Notify V8 GC of memory allocation
|
|
||||||
NanAdjustExternalMemory(static_cast<int>(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());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user