diff --git a/src/Image.cc b/src/Image.cc index 9dff513..e94d0aa 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -613,17 +613,18 @@ Image::loadJPEGFromBuffer(uint8_t *buf, unsigned len) { // Data alloc int stride = width * 4; uint8_t *data = (uint8_t *) malloc(width * height * 4); + if (!data) { - jpeg_finish_decompress(&info); - jpeg_destroy_decompress(&info); - return CAIRO_STATUS_NO_MEMORY; + jpeg_finish_decompress(&info); + jpeg_destroy_decompress(&info); + return CAIRO_STATUS_NO_MEMORY; } uint8_t *src = (uint8_t *) malloc(width * 3); if (!src) { free(data); - jpeg_finish_decompress(&info); - jpeg_destroy_decompress(&info); + jpeg_finish_decompress(&info); + jpeg_destroy_decompress(&info); return CAIRO_STATUS_NO_MEMORY; } @@ -683,19 +684,21 @@ Image::loadJPEG(FILE *stream) { // Data alloc int stride = width * 4; uint8_t *data = (uint8_t *) malloc(width * height * 4); + if (!data) { - fclose(stream); - jpeg_finish_decompress(&info); - jpeg_destroy_decompress(&info); - return CAIRO_STATUS_NO_MEMORY; + fclose(stream); + jpeg_finish_decompress(&info); + jpeg_destroy_decompress(&info); + return CAIRO_STATUS_NO_MEMORY; } - + uint8_t *src = (uint8_t *) malloc(width * 3); + if (!src) { free(data); - fclose(stream); - jpeg_finish_decompress(&info); - jpeg_destroy_decompress(&info); + fclose(stream); + jpeg_finish_decompress(&info); + jpeg_destroy_decompress(&info); return CAIRO_STATUS_NO_MEMORY; }