Use malloc for Nan::NewBuffer owned data

GC results in free() rather than delete[]

Add plenty of new valgrind suppressions
This commit is contained in:
Lovell Fuller 2015-08-24 16:14:49 +01:00
parent b7e0a6f277
commit 4e67a5025a
4 changed files with 166 additions and 7 deletions

View File

@ -23,7 +23,7 @@
"clean": "rm -rf test/fixtures/output.*", "clean": "rm -rf test/fixtures/output.*",
"test": "VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=20000 ./test/unit/*.js", "test": "VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=20000 ./test/unit/*.js",
"test-clean": "npm run clean && npm install && npm test", "test-clean": "npm run clean && npm install && npm test",
"test-leak": "cd test/leak; ./leak.sh; cd - > /dev/null", "test-leak": "./test/leak/leak.sh",
"test-win32-node": "node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js", "test-win32-node": "node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js",
"test-win32-iojs": "iojs ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js" "test-win32-iojs": "iojs ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js"
}, },

View File

@ -142,7 +142,7 @@ class MetadataWorker : public AsyncWorker {
size_t exifLength; size_t exifLength;
if (!vips_image_get_blob(image, VIPS_META_EXIF_NAME, &exif, &exifLength)) { if (!vips_image_get_blob(image, VIPS_META_EXIF_NAME, &exif, &exifLength)) {
baton->exifLength = exifLength; baton->exifLength = exifLength;
baton->exif = new char[exifLength]; baton->exif = static_cast<char*>(malloc(exifLength));
memcpy(baton->exif, exif, exifLength); memcpy(baton->exif, exif, exifLength);
} }
} }
@ -152,7 +152,7 @@ class MetadataWorker : public AsyncWorker {
size_t iccLength; size_t iccLength;
if (!vips_image_get_blob(image, VIPS_META_ICC_NAME, &icc, &iccLength)) { if (!vips_image_get_blob(image, VIPS_META_ICC_NAME, &icc, &iccLength)) {
baton->iccLength = iccLength; baton->iccLength = iccLength;
baton->icc = new char[iccLength]; baton->icc = static_cast<char*>(malloc(iccLength));
memcpy(baton->icc, icc, iccLength); memcpy(baton->icc, icc, iccLength);
} }
} }

View File

@ -1,8 +1,18 @@
#!/bin/sh
if ! type valgrind >/dev/null; then if ! type valgrind >/dev/null; then
echo "Please install valgrind before running memory leak tests" echo "Please install valgrind before running memory leak tests"
exit 1 exit 1
fi fi
curl -O https://raw.githubusercontent.com/jcupitt/libvips/master/libvips.supp curl -o ./test/leak/libvips.supp https://raw.githubusercontent.com/jcupitt/libvips/master/libvips.supp
cd ../../
G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --suppressions=test/leak/libvips.supp --suppressions=test/leak/sharp.supp --leak-check=full --show-leak-kinds=definite,indirect,possible --num-callers=20 --trace-children=yes npm test G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind \
--suppressions=test/leak/libvips.supp \
--suppressions=test/leak/sharp.supp \
--gen-suppressions=yes \
--leak-check=full \
--show-leak-kinds=definite,indirect,possible \
--num-callers=20 \
--trace-children=yes \
npm test

151
test/leak/sharp.supp Executable file → Normal file
View File

@ -30,7 +30,61 @@
fun:jpeg_finish_compress fun:jpeg_finish_compress
} }
# libvips interpolator warnings # libpng
{
cond_libpng_png_read_row
Memcheck:Cond
...
fun:png_read_row
}
{
value_libpng_png_read_row
Memcheck:Value8
...
fun:png_read_row
}
{
cond_libpng_png_write_rows
Memcheck:Cond
...
fun:png_write_row
fun:png_write_rows
}
{
value_libpng_png_write_rows
Memcheck:Value8
...
fun:png_write_row
fun:png_write_rows
}
# libwebp
{
cond_libwebp_WebPEncodeRGBA
Memcheck:Cond
...
fun:WebPEncodeRGBA
}
{
value_libwebp_WebPEncodeRGBA
Memcheck:Value8
...
fun:WebPEncodeRGBA
}
{
cond_libwebp_WebPEncodeRGB
Memcheck:Cond
...
fun:WebPEncodeRGB
}
{
value_libwebp_WebPEncodeRGB
Memcheck:Value8
...
fun:WebPEncodeRGB
}
# libvips
{ {
cond_libvips_interpolate_lbb cond_libvips_interpolate_lbb
Memcheck:Cond Memcheck:Cond
@ -38,6 +92,18 @@
fun:_ZL32vips_interpolate_lbb_interpolateP16_VipsInterpolatePvP11_VipsRegiondd fun:_ZL32vips_interpolate_lbb_interpolateP16_VipsInterpolatePvP11_VipsRegiondd
fun:vips_affine_gen fun:vips_affine_gen
} }
{
cond_libvips_conv_gen
Memcheck:Cond
fun:conv_gen
fun:vips_region_generate
}
{
cond_libvips_col_sRGB2scRGB_8
Memcheck:Value8
fun:vips_col_sRGB2scRGB_8
fun:vips_sRGB2scRGB_gen
}
# libuv warnings # libuv warnings
{ {
@ -46,6 +112,19 @@
... ...
fun:uv__work_done fun:uv__work_done
} }
{
param_libuv_fs_work
Memcheck:Param
write(buf)
...
fun:uv__fs_work
}
{
cond_libuv_work_done
Memcheck:Cond
...
fun:uv__work_done
}
# nodejs warnings # nodejs warnings
{ {
@ -55,6 +134,13 @@
... ...
obj:/usr/bin/nodejs obj:/usr/bin/nodejs
} }
{
param_iojs_write_buffer
Memcheck:Param
write(buf)
...
obj:/usr/bin/iojs
}
{ {
leak_nodejs_ImmutableAsciiSource_CreateFromLiteral leak_nodejs_ImmutableAsciiSource_CreateFromLiteral
Memcheck:Leak Memcheck:Leak
@ -99,6 +185,69 @@
... ...
fun:ares_init_options fun:ares_init_options
} }
{
leak_nodejs_CreateEnvironment_Handle
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN4node17CreateEnvironmentEPN2v87IsolateEP9uv_loop_sNS0_6HandleINS0_7ContextEEEiPKPKciSB_
}
{
leak_nodejs_CreateEnvironment_Local
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN4node17CreateEnvironmentEPN2v87IsolateEP9uv_loop_sNS0_5LocalINS0_7ContextEEEiPKPKciSB_
}
{
leak_nan_FunctionCallbackInfo
Memcheck:Leak
match-leak-kinds: definite
...
fun:_ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE
}
{
leak_v8_FunctionCallbackInfo
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE
}
{
leak_v8_CallInterfaceDescriptorData
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN2v88internal27CallInterfaceDescriptorData10InitializeEiPNS0_8RegisterEPNS0_14RepresentationEPNS0_27PlatformInterfaceDescriptorE
}
{
leak_v8_Isolate_Init
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN2v88internal7Isolate4InitEPNS0_12DeserializerE
}
{
leak_v8_StoreDescriptor_Initialize
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN2v88internal15StoreDescriptor10InitializeEPNS0_27CallInterfaceDescriptorDataE
}
{
leak_v8_CodeStub_GetCode
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN2v88internal8CodeStub7GetCodeEv
}
{
leak_v8_CreateICUCollator
Memcheck:Leak
match-leak-kinds: possible
...
fun:_ZN2v88internal12_GLOBAL__N_117CreateICUCollatorEPNS0_7IsolateERKN6icu_556LocaleENS0_6HandleINS0_8JSObjectEEE
}
# vips__init warnings # vips__init warnings
{ {