From 49db946aa2a22de6e87fd602e74e3fa3d7666eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Thu, 20 Jun 2019 00:40:09 +0200 Subject: [PATCH] load_jpeg.c Clean code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch returns NULL, because the variable image is not used yet. The patch also removes three lines: - buffer[0] = NULL; /* Initialize pointer to avoid spurious free in cleanup code */ RErrorCode = RERR_BADIMAGEFILE; jpeg_destroy_decompress(&cinfo); fclose(file); - if (buffer[0]) - free(buffer[0]); buffer is a local variable. The malloc is not used yet. So: - We set the value to NULL, then check if is null to call free(). So the free() call is never used. We can remove the last too lines. - We don't need set now to NULL, because the variable is empty (the initializated (or not) value is not used, and is destroyed as local variable when we returns, just one line later. Signed-off-by: Rodolfo García Peñas (kix) --- wrlib/load_jpeg.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/wrlib/load_jpeg.c b/wrlib/load_jpeg.c index 696048cf..02d53a57 100644 --- a/wrlib/load_jpeg.c +++ b/wrlib/load_jpeg.c @@ -132,14 +132,10 @@ RImage *RLoadJPEG(const char *file_name) 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); - if (buffer[0]) - free(buffer[0]); - - return image; + return NULL; } buffer[0] = (JSAMPROW) malloc(cinfo.image_width * cinfo.num_components);