Browse Source

Merge pull request #365 from kkoopa/memleakspull

Revised fix of memory leak #318
v1.x
Juriy Zaytsev 11 years ago
parent
commit
285dc4f865
  1. 12
      src/Image.cc
  2. 13
      src/JPEGStream.h

12
src/Image.cc

@ -314,6 +314,16 @@ Image::Image() {
Image::~Image() {
clearData();
if (onerror) {
delete onerror;
onerror = NULL;
}
if (onload) {
delete onload;
onload = NULL;
}
}
/*
@ -346,6 +356,7 @@ Image::loaded() {
if (onload != NULL) {
onload->Call(0, NULL);
delete onload;
onload = NULL;
}
}
@ -360,6 +371,7 @@ Image::error(Local<Value> err) {
Local<Value> argv[1] = { err };
onerror->Call(1, argv);
delete onerror;
onerror = NULL;
}
}

13
src/JPEGStream.h

@ -30,6 +30,7 @@ init_closure_destination(j_compress_ptr cinfo){
boolean
empty_closure_output_buffer(j_compress_ptr cinfo){
NanScope();
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest;
Local<Object> buf = NanNewBufferHandle((char *)dest->buffer, dest->bufsize);
Local<Value> argv[3] = {
@ -45,6 +46,7 @@ empty_closure_output_buffer(j_compress_ptr cinfo){
void
term_closure_destination(j_compress_ptr cinfo){
NanScope();
closure_destination_mgr *dest = (closure_destination_mgr *) cinfo->dest;
/* emit remaining data */
size_t remaining = dest->bufsize - cinfo->dest->free_in_buffer;
@ -95,6 +97,16 @@ jpeg_closure_dest(j_compress_ptr cinfo, closure_t * closure, int bufsize){
cinfo->dest->free_in_buffer = dest->bufsize;
}
void
jpeg_free_custom_allocations(j_compress_ptr cinfo){
closure_destination_mgr * dest;
dest = (closure_destination_mgr *) cinfo->dest;
if (dest->buffer) {
free(dest->buffer);
dest->buffer = NULL;
}
}
void
write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, bool progressive, closure_t *closure){
int w = cairo_image_surface_get_width(surface);
@ -137,6 +149,7 @@ write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, bool pr
}
free(dst);
jpeg_finish_compress(&cinfo);
jpeg_free_custom_allocations(&cinfo);
jpeg_destroy_compress(&cinfo);
}

Loading…
Cancel
Save