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

Closed
asuwend1 opened this Issue Jun 20, 2012 · 1 comment

2 participants

@asuwend1

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) (Image.cc:677)
==30936== by 0x65739AB: Image::loadJPEG(_IO_FILE
) (Image.cc:871)
==30936== by 0x6573AA0: Image::loadSurface() (Image.cc:409)
==30936== by 0x6573FD3: Image::SetSource(v8::Localv8::String, v8::Localv8::Value, v8::AccessorInfo const&) (Image.cc:188)

...

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: http://www.coolcarsphotos.com/wp-content/uploads/2011/11/mazda-furai-race-car-hd-wallpaper.jpg
//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--) {
leakingFunction();
}

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
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