From c9f991b8de07d1d92a3fb20c92565e0e56147ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bj=C3=B6rklund?= Date: Wed, 25 Apr 2012 23:43:05 +0200 Subject: [PATCH] Fixes the Image memory leak (#150). It is basically the fix from @AllYearbooks fork without the mime-stuff. --- src/Image.cc | 7 +++++-- src/Image.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Image.cc b/src/Image.cc index 86b70a5..ab75bf1 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -240,6 +240,7 @@ Image::SetOnerror(Local, Local val, const AccessorInfo &info) { */ Image::Image() { + live_data = NULL; filename = NULL; _surface = NULL; width = height = 0; @@ -255,6 +256,8 @@ Image::~Image() { V8::AdjustAmountOfExternalAllocatedMemory(-4 * width * height); cairo_surface_destroy(_surface); } + + if (live_data) free(live_data); if (filename) free(filename); } @@ -544,7 +547,7 @@ Image::loadGIFFromBuffer(uint8_t *buf, unsigned len) { free(data); return status; } - + live_data = data; return CAIRO_STATUS_SUCCESS; } #endif /* HAVE_GIF */ @@ -665,7 +668,7 @@ Image::loadJPEGFromBuffer(uint8_t *buf, unsigned len) { free(data); return status; } - + live_data = data; return CAIRO_STATUS_SUCCESS; } diff --git a/src/Image.h b/src/Image.h index 2d2ceb4..5e6fda4 100644 --- a/src/Image.h +++ b/src/Image.h @@ -70,6 +70,7 @@ class Image: public node::ObjectWrap { private: cairo_surface_t *_surface; + uint8_t *live_data; ~Image(); };