From 4e67a5025a9236b1bdb7544e01a41479bf3c95be Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 24 Aug 2015 16:14:49 +0100 Subject: [PATCH] Use malloc for Nan::NewBuffer owned data GC results in free() rather than delete[] Add plenty of new valgrind suppressions --- package.json | 2 +- src/metadata.cc | 4 +- test/leak/leak.sh | 16 ++++- test/leak/sharp.supp | 151 ++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 166 insertions(+), 7 deletions(-) mode change 100755 => 100644 test/leak/sharp.supp diff --git a/package.json b/package.json index b8f80f9f..53a0763b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "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-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-iojs": "iojs ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js" }, diff --git a/src/metadata.cc b/src/metadata.cc index 4803e7f1..0b1ef39b 100755 --- a/src/metadata.cc +++ b/src/metadata.cc @@ -142,7 +142,7 @@ class MetadataWorker : public AsyncWorker { size_t exifLength; if (!vips_image_get_blob(image, VIPS_META_EXIF_NAME, &exif, &exifLength)) { baton->exifLength = exifLength; - baton->exif = new char[exifLength]; + baton->exif = static_cast(malloc(exifLength)); memcpy(baton->exif, exif, exifLength); } } @@ -152,7 +152,7 @@ class MetadataWorker : public AsyncWorker { size_t iccLength; if (!vips_image_get_blob(image, VIPS_META_ICC_NAME, &icc, &iccLength)) { baton->iccLength = iccLength; - baton->icc = new char[iccLength]; + baton->icc = static_cast(malloc(iccLength)); memcpy(baton->icc, icc, iccLength); } } diff --git a/test/leak/leak.sh b/test/leak/leak.sh index e55605a9..dc4c09ee 100755 --- a/test/leak/leak.sh +++ b/test/leak/leak.sh @@ -1,8 +1,18 @@ +#!/bin/sh + if ! type valgrind >/dev/null; then echo "Please install valgrind before running memory leak tests" exit 1 fi -curl -O 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 +curl -o ./test/leak/libvips.supp https://raw.githubusercontent.com/jcupitt/libvips/master/libvips.supp + +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 diff --git a/test/leak/sharp.supp b/test/leak/sharp.supp old mode 100755 new mode 100644 index 58d4ac58..93cf30e4 --- a/test/leak/sharp.supp +++ b/test/leak/sharp.supp @@ -30,7 +30,61 @@ 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 Memcheck:Cond @@ -38,6 +92,18 @@ fun:_ZL32vips_interpolate_lbb_interpolateP16_VipsInterpolatePvP11_VipsRegiondd 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 { @@ -46,6 +112,19 @@ ... 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 { @@ -55,6 +134,13 @@ ... obj:/usr/bin/nodejs } +{ + param_iojs_write_buffer + Memcheck:Param + write(buf) + ... + obj:/usr/bin/iojs +} { leak_nodejs_ImmutableAsciiSource_CreateFromLiteral Memcheck:Leak @@ -99,6 +185,69 @@ ... 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 {