From 52e24d893f76d41b75409d8676f34e5d9645abb1 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Fri, 11 Mar 2011 10:48:10 -0800 Subject: [PATCH] free data if src malloc() fails --- src/Image.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) {