Browse Source

Fixes the Image memory leak (#150). It is basically the fix from @AllYearbooks fork without the mime-stuff.

v1.x
David Björklund 13 years ago
parent
commit
c9f991b8de
  1. 7
      src/Image.cc
  2. 1
      src/Image.h

7
src/Image.cc

@ -240,6 +240,7 @@ Image::SetOnerror(Local<String>, Local<Value> val, const AccessorInfo &info) {
*/ */
Image::Image() { Image::Image() {
live_data = NULL;
filename = NULL; filename = NULL;
_surface = NULL; _surface = NULL;
width = height = 0; width = height = 0;
@ -255,6 +256,8 @@ Image::~Image() {
V8::AdjustAmountOfExternalAllocatedMemory(-4 * width * height); V8::AdjustAmountOfExternalAllocatedMemory(-4 * width * height);
cairo_surface_destroy(_surface); cairo_surface_destroy(_surface);
} }
if (live_data) free(live_data);
if (filename) free(filename); if (filename) free(filename);
} }
@ -544,7 +547,7 @@ Image::loadGIFFromBuffer(uint8_t *buf, unsigned len) {
free(data); free(data);
return status; return status;
} }
live_data = data;
return CAIRO_STATUS_SUCCESS; return CAIRO_STATUS_SUCCESS;
} }
#endif /* HAVE_GIF */ #endif /* HAVE_GIF */
@ -665,7 +668,7 @@ Image::loadJPEGFromBuffer(uint8_t *buf, unsigned len) {
free(data); free(data);
return status; return status;
} }
live_data = data;
return CAIRO_STATUS_SUCCESS; return CAIRO_STATUS_SUCCESS;
} }

1
src/Image.h

@ -70,6 +70,7 @@ class Image: public node::ObjectWrap {
private: private:
cairo_surface_t *_surface; cairo_surface_t *_surface;
uint8_t *live_data;
~Image(); ~Image();
}; };

Loading…
Cancel
Save