diff --git a/src/Image.cc b/src/Image.cc index c5c2e54..41baf34 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -305,7 +305,10 @@ Image::loadJPEG() { if (!data) return ThrowException(Canvas::Error(CAIRO_STATUS_NO_MEMORY)); uint8_t *src = (uint8_t *) malloc(width * 3); - if (!src) return ThrowException(Canvas::Error(CAIRO_STATUS_NO_MEMORY)); + if (!src) { + free(data); + return ThrowException(Canvas::Error(CAIRO_STATUS_NO_MEMORY)); + } // Copy RGB -> ARGB for (int y = 0; y < height; ++y) {