mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
wraster: Remove duplicate code
Duplicating things makes maintenance error-prone, which is not a good idea. In case the abort procedure would need an update, it would be easy then to forget some place, leading to leaks, if not worse. Beside, goto is not as bad as academics would like people to believe, when it is used correctly (and this case is one of them). The name for the label was given an explicit meaning to make code easy to understand. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
8aecba27d1
commit
920c6d16b1
@@ -130,18 +130,15 @@ RImage *RLoadJPEG(const char *file_name)
|
||||
jpeg_stdio_src(&cinfo, file);
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
if (cinfo.image_width < 1 || cinfo.image_height < 1) {
|
||||
buffer[0] = NULL; /* Initialize pointer to avoid spurious free in cleanup code */
|
||||
RErrorCode = RERR_BADIMAGEFILE;
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
goto abort_and_release_resources;
|
||||
}
|
||||
|
||||
buffer[0] = (JSAMPROW) malloc(cinfo.image_width * cinfo.num_components);
|
||||
if (!buffer[0]) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
return NULL;
|
||||
goto abort_and_release_resources;
|
||||
}
|
||||
|
||||
if (cinfo.jpeg_color_space == JCS_GRAYSCALE)
|
||||
@@ -156,12 +153,7 @@ RImage *RLoadJPEG(const char *file_name)
|
||||
image = RCreateImage(cinfo.image_width, cinfo.image_height, False);
|
||||
if (!image) {
|
||||
RErrorCode = RERR_NOMEMORY;
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
if (buffer[0])
|
||||
free(buffer[0]);
|
||||
|
||||
return NULL;
|
||||
goto abort_and_release_resources;
|
||||
}
|
||||
|
||||
jpeg_start_decompress(&cinfo);
|
||||
@@ -186,6 +178,8 @@ RImage *RLoadJPEG(const char *file_name)
|
||||
}
|
||||
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
|
||||
abort_and_release_resources:
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
if (buffer[0])
|
||||
|
||||
Reference in New Issue
Block a user