Browse Source

Added error cleanup code to the JPEG loader functions

v1.x
obarthel 13 years ago
committed by Tj Holowaychuk
parent
commit
4cfb7a61b2
  1. 18
      src/Image.cc

18
src/Image.cc

@ -613,11 +613,17 @@ Image::loadJPEGFromBuffer(uint8_t *buf, unsigned len) {
// Data alloc
int stride = width * 4;
uint8_t *data = (uint8_t *) malloc(width * height * 4);
if (!data) return CAIRO_STATUS_NO_MEMORY;
if (!data) {
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);
return CAIRO_STATUS_NO_MEMORY;
}
@ -677,11 +683,19 @@ Image::loadJPEG(FILE *stream) {
// Data alloc
int stride = width * 4;
uint8_t *data = (uint8_t *) malloc(width * height * 4);
if (!data) return CAIRO_STATUS_NO_MEMORY;
if (!data) {
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);
return CAIRO_STATUS_NO_MEMORY;
}

Loading…
Cancel
Save