Skip to content

Commit

Permalink
Use FreeCallback to support mixed Windows runtime libs #152
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Nov 14, 2015
1 parent ede2ee9 commit 2678d76
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
6 changes: 3 additions & 3 deletions binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ var error = function(msg) {
module.exports.download_vips = function() {
// Has vips been installed locally?
if (!isFile(vipsHeaderPath)) {
// 32-bit
if (process.arch === 'ia32') {
error('32-bit systems require manual installation - please see http://sharp.dimens.io/en/stable/install/');
// Ensure 64-bit
if (process.arch !== 'x64') {
error('ARM and 32-bit systems require manual installation - please see http://sharp.dimens.io/en/stable/install/');
}
// Ensure libc >= 2.15
var lddVersion = process.env.LDD_VERSION;
Expand Down
9 changes: 9 additions & 0 deletions src/common.cc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@ namespace sharp {
return window_size;
}

/*
Called when a Buffer undergoes GC, required to support mixed runtime libraries in Windows
*/
void FreeCallback(char* data, void* hint) {
if (data != NULL) {
g_free(data);
}
}

} // namespace sharp
5 changes: 5 additions & 0 deletions src/common.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ namespace sharp {
*/
int InterpolatorWindowSize(char const *name);

/*
Called when a Buffer undergoes GC, required to support mixed runtime libraries in Windows
*/
void FreeCallback(char* data, void* hint);

} // namespace sharp

#endif // SRC_COMMON_H_
11 changes: 9 additions & 2 deletions src/metadata.cc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using sharp::InitImage;
using sharp::HasProfile;
using sharp::HasAlpha;
using sharp::ExifOrientation;
using sharp::FreeCallback;
using sharp::counterQueue;

struct MetadataBaton {
Expand Down Expand Up @@ -175,10 +176,16 @@ class MetadataWorker : public AsyncWorker {
Set(info, New("orientation").ToLocalChecked(), New<Number>(baton->orientation));
}
if (baton->exifLength > 0) {
Set(info, New("exif").ToLocalChecked(), NewBuffer(baton->exif, baton->exifLength).ToLocalChecked());
Set(info,
New("exif").ToLocalChecked(),
NewBuffer(baton->exif, baton->exifLength, FreeCallback, nullptr).ToLocalChecked()
);
}
if (baton->iccLength > 0) {
Set(info, New("icc").ToLocalChecked(), NewBuffer(baton->icc, baton->iccLength).ToLocalChecked());
Set(info,
New("icc").ToLocalChecked(),
NewBuffer(baton->icc, baton->iccLength, FreeCallback, nullptr).ToLocalChecked()
);
}
argv[1] = info;
}
Expand Down
5 changes: 4 additions & 1 deletion src/pipeline.cc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ using sharp::IsPng;
using sharp::IsWebp;
using sharp::IsTiff;
using sharp::IsDz;
using sharp::FreeCallback;
using sharp::counterProcess;
using sharp::counterQueue;

Expand Down Expand Up @@ -959,7 +960,9 @@ class PipelineWorker : public AsyncWorker {

if (baton->bufferOutLength > 0) {
// Pass ownership of output data to Buffer instance
argv[1] = NewBuffer(static_cast<char*>(baton->bufferOut), baton->bufferOutLength).ToLocalChecked();
argv[1] = NewBuffer(
static_cast<char*>(baton->bufferOut), baton->bufferOutLength, FreeCallback, nullptr
).ToLocalChecked();
// Add buffer size to info
Set(info, New("size").ToLocalChecked(), New<Uint32>(static_cast<uint32_t>(baton->bufferOutLength)));
argv[2] = info;
Expand Down
7 changes: 7 additions & 0 deletions test/leak/sharp.supp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@
...
fun:get_bands
}
{
value_magick_is_palette_image
Memcheck:Value8
fun:IsPaletteImage
...
fun:get_bands
}

# glib g_file_read_link
# https://github.com/GNOME/glib/commit/49a5d0f6f2aed99cd78f25655f137f4448e47d92
Expand Down

0 comments on commit 2678d76

Please sign in to comment.