diff --git a/src/Image.cc b/src/Image.cc index 72c5df5..cbb41db 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -346,6 +346,11 @@ Image::loaded() { if (onload != NULL) { onload->Call(0, NULL); delete onload; + onload = NULL; + } + if (onerror != NULL) { + delete onerror; + onerror = NULL; } } @@ -360,6 +365,11 @@ Image::error(Local err) { Local argv[1] = { err }; onerror->Call(1, argv); delete onerror; + onerror = NULL; + } + if (onload != NULL) { + delete onload; + onload = NULL; } } diff --git a/src/JPEGStream.h b/src/JPEGStream.h index 0e0738c..041b950 100644 --- a/src/JPEGStream.h +++ b/src/JPEGStream.h @@ -95,6 +95,13 @@ 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; + free(dest->buffer); +} + 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); @@ -136,6 +143,7 @@ write_to_jpeg_stream(cairo_surface_t *surface, int bufsize, int quality, bool pr sl++; } free(dst); + jpeg_free_custom_allocations(&cinfo); jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); }