Improve __image_util_decode_read_header() 29/236529/3
authorhj kim <backto.kim@samsung.com>
Thu, 18 Jun 2020 01:47:55 +0000 (10:47 +0900)
committerhj kim <backto.kim@samsung.com>
Thu, 18 Jun 2020 06:46:09 +0000 (15:46 +0900)
Change-Id: I2c8b7395901299f1cafb29e47f933d1b9345ddec

src/image_util_decode.c

index 6019314..9498652 100644 (file)
@@ -56,26 +56,17 @@ static int __image_util_decode_read_header(const char *path, unsigned char **buf
                }
        }
 
-       read_buffer = (void *)calloc(1, IMG_HEADER_LENGTH + 1);
-       if (read_buffer == NULL) {
-               image_util_error("Allocation fail");
-               fclose(fp);
-               fp = NULL;
-               return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
-       }
+       read_buffer = g_malloc0(IMG_HEADER_LENGTH + 1);
 
        if (fread(read_buffer, 1, IMG_HEADER_LENGTH, fp) != IMG_HEADER_LENGTH) {
-               image_util_error("File read failed");
+               image_util_error("Fail to File read");
                fclose(fp);
-               fp = NULL;
-               IMAGE_UTIL_SAFE_FREE(read_buffer);
+               g_free(read_buffer);
                return IMAGE_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       *buffer = read_buffer;
-
        fclose(fp);
-       fp = NULL;
+       *buffer = read_buffer;
 
        return IMAGE_UTIL_ERROR_NONE;
 }