Destructor ~Image() in not called in this case? #179

asuwend1 opened this Issue Jun 20, 2012 · 1 comment

2 participants


I was recently looking into an uncontrolled heap growth issue that seemed to be fixed now. However I am still seeing this in Valgrind report (with --show-reachable=yes flag):

==30936== 127,844,352 bytes in 4 blocks are still reachable in loss record 108 of 108
==30936== at 0x4A0610C: malloc (vg_replace_malloc.c:195)
==30936== by 0x6572DE7: Image::decodeJPEGIntoSurface(jpeg_decompress_struct) (
==30936== by 0x65739AB: Image::loadJPEG(_IO_FILE
) (
==30936== by 0x6573AA0: Image::loadSurface() (
==30936== by 0x6573FD3: Image::SetSource(v8::Localv8::String, v8::Localv8::Value, v8::AccessorInfo const&) (


It looks like this malloc is never freed:
uint8_t *data = (uint8_t *) malloc(width * height * 4);
(later on in decodeJPEGIntoSurface(): _data = data. In theory, _data should be freed when the Image destructor was called - but the destructor was never called).

Here's how I use node-canvas:

#!/usr/bin/env node

var Canvas = require('/home/asuwend1/pworkspace/node-canvas'),
Image = Canvas.Image;

//VARS TO CUSTOMIZE: imageLocation
var iterations = 4;
//image that I used:
//any JPEG should be fine
var imageLocation = './car.jpg';

var i;
var leakingFunction = function() {

var canvasImg = new Image();
canvasImg.src = imageLocation;


for(i=iterations; i>0; i--) {

Here's how I run valgrind:
valgrind --leak-check=yes --show-reachable=yes node imageDestructorNotCalled.js

Any thought why the ~Image() didn't get called?

Thanks in advance.

tj commented Jun 20, 2012

hmm looks fine at a glance

@asuwend1 asuwend1 closed this Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment