< prev index next >
modules/javafx.graphics/src/main/native-iio/jpegloader.c
Print this page
@@ -1336,10 +1336,12 @@
if (setjmp(jerr_mgr->setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error. */
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo,
buffer);
+ free(cinfo);
+ free(jerr_mgr);
ThrowByName(env, "java/io/IOException", buffer);
return 0;
}
/* Perform library initialization */
@@ -1353,10 +1355,12 @@
* Now set up our source.
*/
cinfo->src =
(struct jpeg_source_mgr *) malloc(sizeof (struct jpeg_source_mgr));
if (cinfo->src == NULL) {
+ free(cinfo);
+ free(jerr_mgr);
ThrowByName(env,
"java/lang/OutOfMemoryError",
"Initializing Reader");
return 0;
}
@@ -1369,19 +1373,27 @@
cinfo->src->term_source = imageio_term_source;
/* set up the association to persist for future calls */
data = initImageioData(env, (j_common_ptr) cinfo, this);
if (data == NULL) {
+ free(cinfo->src);
+ free(cinfo);
+ free(jerr_mgr);
ThrowByName(env,
"java/lang/OutOfMemoryError",
"Initializing Reader");
return 0;
}
imageio_set_stream(env, (j_common_ptr) cinfo, data, stream);
- if ((*env)->ExceptionCheck(env)) return 0;
+ if ((*env)->ExceptionCheck(env)) {
+ free(cinfo->src);
+ free(cinfo);
+ free(jerr_mgr);
+ return 0;
+ }
imageio_init_source((j_decompress_ptr) cinfo);
src = cinfo->src;
jerr = (sun_jpeg_error_ptr) cinfo->err;
@@ -1395,14 +1407,21 @@
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo,
buffer);
ThrowByName(env, "java/io/IOException", buffer);
}
+ free(cinfo->src);
+ free(cinfo);
+ free(jerr_mgr);
return 0;
}
if (GET_ARRAYS(env, data, &src->next_input_byte) == NOT_OK) {
+ RELEASE_ARRAYS(env, data, src->next_input_byte);
+ free(cinfo->src);
+ free(cinfo);
+ free(jerr_mgr);
ThrowByName(env,
"java/io/IOException",
"Array pin failed");
return 0;
}
@@ -1498,10 +1517,13 @@
/* read icc profile data */
profileData = read_icc_profile(env, cinfo);
if ((*env)->ExceptionCheck(env)) {
+ free(cinfo->src);
+ free(cinfo);
+ free(jerr_mgr);
return 0;
}
(*env)->CallVoidMethod(env, this,
JPEGImageLoader_setInputAttributesID,
@@ -1510,10 +1532,13 @@
cinfo->jpeg_color_space,
cinfo->out_color_space,
cinfo->num_components,
profileData);
if ((*env)->ExceptionCheck(env)) {
+ free(cinfo->src);
+ free(cinfo);
+ free(jerr_mgr);
return 0;
}
}
return ptr_to_jlong(data);
@@ -1604,39 +1629,40 @@
imageIODataPtr data = (imageIODataPtr) jlong_to_ptr(ptr);
j_decompress_ptr cinfo = (j_decompress_ptr) data->jpegObj;
struct jpeg_source_mgr *src = cinfo->src;
sun_jpeg_error_ptr jerr;
int bytes_per_row = cinfo->output_width * cinfo->output_components;
- JSAMPROW scanline_ptr = (JSAMPROW) malloc(bytes_per_row * sizeof (JSAMPLE));
int offset = 0;
+ JSAMPROW scanline_ptr = (JSAMPROW) malloc(bytes_per_row * sizeof (JSAMPLE));
+
+ if (scanline_ptr == NULL) {
+ ThrowByName(env,
+ "java/lang/OutOfMemoryError",
+ "Reading JPEG Stream");
+ return JNI_FALSE;
+ }
if (!SAFE_TO_MULT(cinfo->output_width, cinfo->output_components) ||
!SAFE_TO_MULT(bytes_per_row, cinfo->output_height) ||
((*env)->GetArrayLength(env, barray) <
(bytes_per_row * cinfo->output_height)))
{
+ free(scanline_ptr);
ThrowByName(env,
"java/lang/OutOfMemoryError",
"Reading JPEG Stream");
return JNI_FALSE;
}
if (GET_ARRAYS(env, data, &cinfo->src->next_input_byte) == NOT_OK) {
+ free(scanline_ptr);
ThrowByName(env,
"java/io/IOException",
"Array pin failed");
return JNI_FALSE;
}
- if (scanline_ptr == NULL) {
- ThrowByName(env,
- "java/lang/OutOfMemoryError",
- "Reading JPEG Stream");
- RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
- return JNI_FALSE;
- }
-
/* Establish the setjmp return context for sun_jpeg_error_exit to use. */
jerr = (sun_jpeg_error_ptr) cinfo->err;
if (setjmp(jerr->setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error
@@ -1645,13 +1671,11 @@
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo,
buffer);
ThrowByName(env, "java/io/IOException", buffer);
}
- if (scanline_ptr != NULL) {
free(scanline_ptr);
- }
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
return JNI_FALSE;
}
while (cinfo->output_scanline < cinfo->output_height) {
@@ -1659,25 +1683,31 @@
if (report_progress == JNI_TRUE) {
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
(*env)->CallVoidMethod(env, this,
JPEGImageLoader_updateImageProgressID,
cinfo->output_scanline);
- if ((*env)->ExceptionCheck(env)) return JNI_FALSE;
+ if ((*env)->ExceptionCheck(env)) {
+ free(scanline_ptr);
+ return JNI_FALSE;
+ }
if (GET_ARRAYS(env, data, &cinfo->src->next_input_byte) == NOT_OK) {
ThrowByName(env,
"java/io/IOException",
"Array pin failed");
+ free(scanline_ptr);
return JNI_FALSE;
}
}
num_scanlines = jpeg_read_scanlines(cinfo, &scanline_ptr, 1);
if (num_scanlines == 1) {
jboolean iscopy = FALSE;
jbyte *body = (*env)->GetPrimitiveArrayCritical(env, barray, &iscopy);
if (body == NULL) {
fprintf(stderr, "decompressIndirect: GetPrimitiveArrayCritical returns NULL: out of memory\n");
+ free(scanline_ptr);
+ RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
return JNI_FALSE;
}
memcpy(body+offset,scanline_ptr, bytes_per_row);
(*env)->ReleasePrimitiveArrayCritical(env, barray, body, JNI_ABORT);
offset += bytes_per_row;
@@ -1687,15 +1717,19 @@
if (report_progress == JNI_TRUE) {
RELEASE_ARRAYS(env, data, cinfo->src->next_input_byte);
(*env)->CallVoidMethod(env, this,
JPEGImageLoader_updateImageProgressID,
cinfo->output_height);
- if ((*env)->ExceptionCheck(env)) return JNI_FALSE;
+ if ((*env)->ExceptionCheck(env)) {
+ free(scanline_ptr);
+ return JNI_FALSE;
+ }
if (GET_ARRAYS(env, data, &cinfo->src->next_input_byte) == NOT_OK) {
ThrowByName(env,
"java/io/IOException",
"Array pin failed");
+ free(scanline_ptr);
return JNI_FALSE;
}
}
jpeg_finish_decompress(cinfo);
< prev index next >