1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +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:
Christophe CURIS
2021-05-13 18:47:38 +02:00
committed by Carlos R. Mafra
parent 8aecba27d1
commit 920c6d16b1

View File

@@ -130,18 +130,15 @@ RImage *RLoadJPEG(const char *file_name)
jpeg_stdio_src(&cinfo, file); jpeg_stdio_src(&cinfo, file);
jpeg_read_header(&cinfo, TRUE); jpeg_read_header(&cinfo, TRUE);
if (cinfo.image_width < 1 || cinfo.image_height < 1) { if (cinfo.image_width < 1 || cinfo.image_height < 1) {
buffer[0] = NULL; /* Initialize pointer to avoid spurious free in cleanup code */
RErrorCode = RERR_BADIMAGEFILE; RErrorCode = RERR_BADIMAGEFILE;
jpeg_destroy_decompress(&cinfo); goto abort_and_release_resources;
fclose(file);
return NULL;
} }
buffer[0] = (JSAMPROW) malloc(cinfo.image_width * cinfo.num_components); buffer[0] = (JSAMPROW) malloc(cinfo.image_width * cinfo.num_components);
if (!buffer[0]) { if (!buffer[0]) {
RErrorCode = RERR_NOMEMORY; RErrorCode = RERR_NOMEMORY;
jpeg_destroy_decompress(&cinfo); goto abort_and_release_resources;
fclose(file);
return NULL;
} }
if (cinfo.jpeg_color_space == JCS_GRAYSCALE) 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); image = RCreateImage(cinfo.image_width, cinfo.image_height, False);
if (!image) { if (!image) {
RErrorCode = RERR_NOMEMORY; RErrorCode = RERR_NOMEMORY;
jpeg_destroy_decompress(&cinfo); goto abort_and_release_resources;
fclose(file);
if (buffer[0])
free(buffer[0]);
return NULL;
} }
jpeg_start_decompress(&cinfo); jpeg_start_decompress(&cinfo);
@@ -186,6 +178,8 @@ RImage *RLoadJPEG(const char *file_name)
} }
jpeg_finish_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
abort_and_release_resources:
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(file); fclose(file);
if (buffer[0]) if (buffer[0])