Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Image memory leak (#150) #162

Merged
merged 1 commit into from Apr 25, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Image.cc
Expand Up @@ -240,6 +240,7 @@ Image::SetOnerror(Local<String>, Local<Value> val, const AccessorInfo &info) {
*/

Image::Image() {
live_data = NULL;
filename = NULL;
_surface = NULL;
width = height = 0;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -665,7 +668,7 @@ Image::loadJPEGFromBuffer(uint8_t *buf, unsigned len) {
free(data);
return status;
}

live_data = data;
return CAIRO_STATUS_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions src/Image.h
Expand Up @@ -70,6 +70,7 @@ class Image: public node::ObjectWrap {

private:
cairo_surface_t *_surface;
uint8_t *live_data;
~Image();
};

Expand Down