Fix coverity issue (#1085447) 11/213311/3 accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.025952 accepted/tizen/5.5/unified/mobile/hotfix/20201027.064729 accepted/tizen/unified/20190904.224447 submit/tizen/20190904.082736 submit/tizen_5.5/20191031.000002 submit/tizen_5.5_mobile_hotfix/20201026.185102 tizen_5.5.m2_release
authorjiyong.min <jiyong.min@samsung.com>
Wed, 4 Sep 2019 06:37:50 +0000 (15:37 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Wed, 4 Sep 2019 07:24:56 +0000 (16:24 +0900)
Change-Id: Ib9d77ca07988192b403b81011ff96326173a5624

src/image_util_decode.c

index 110e021..1b2c000 100644 (file)
@@ -599,14 +599,29 @@ int image_util_decode_destroy(image_util_decode_h handle)
 }
 
 #ifdef TIZEN_FEATURE_COMPATIBILITY
-int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
+static int __image_util_get_image(mm_util_image_h image, int *width, int *height, unsigned char **buffer, unsigned int *size)
 {
        int err = MM_UTIL_ERROR_NONE;
-       mm_util_image_h image = NULL;
        unsigned int image_width = 0;
        unsigned int image_height = 0;
        size_t image_size = 0;
 
+       err = mm_image_get_image(image, &image_width, &image_height, NULL, buffer, &image_size);
+       if (width)
+               *width = image_width;
+       if (height)
+               *height = image_height;
+       if (size)
+               *size = image_size;
+
+       return err;
+}
+
+int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
+{
+       int err = MM_UTIL_ERROR_NONE;
+       mm_util_image_h image = NULL;
+
        image_util_warning("DEPRECATION WARNING: image_util_decode_jpeg() is removed from 5.0. Use image_util_decode_create() instead.");
 
        image_util_retvm_if(!IMAGE_UTIL_STRING_VALID(path), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid path");
@@ -618,12 +633,8 @@ int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace,
        err = mm_util_decode_from_jpeg_file(path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &image);
        image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "mm_util_decode_from_jpeg_file failed. (%d)", err);
 
-       err = mm_image_get_image(image, &image_width, &image_height, NULL, image_buffer, &image_size);
-       if (width)
-               *width = image_width;
-       if (height)
-               *height = image_height;
-       *size = image_size;
+       err = __image_util_get_image(image, width, height, image_buffer, size);
+       mm_image_destroy_image(image);
 
        return _image_error_capi(err);
 }
@@ -632,9 +643,6 @@ int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpe
 {
        int err = MM_UTIL_ERROR_NONE;
        mm_util_image_h image = NULL;
-       unsigned int image_width = 0;
-       unsigned int image_height = 0;
-       size_t image_size = 0;
 
        image_util_warning("DEPRECATION WARNING: image_util_decode_jpeg_from_memory() is removed from 5.0. Use image_util_decode_create() instead.");
 
@@ -647,14 +655,10 @@ int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpe
 
        err = mm_util_decode_from_jpeg_memory((void  *)jpeg_buffer, (size_t)jpeg_size,
                                        TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1, &image);
-       image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "mm_util_decode_from_jpeg_file failed. (%d)", err);
+       image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "image_util_decode_jpeg_from_memory failed. (%d)", err);
 
-       err = mm_image_get_image(image, &image_width, &image_height, NULL, image_buffer, &image_size);
-       if (width)
-               *width = image_width;
-       if (height)
-               *height = image_height;
-       *size = image_size;
+       err = __image_util_get_image(image, width, height, image_buffer, size);
+       mm_image_destroy_image(image);
 
        return _image_error_capi(err);
 }
@@ -663,9 +667,6 @@ int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspac
 {
        int err = MM_UTIL_ERROR_NONE;
        mm_util_image_h image = NULL;
-       unsigned int image_width = 0;
-       unsigned int image_height = 0;
-       size_t image_size = 0;
 
        image_util_warning("DEPRECATION WARNING: image_util_decode_jpeg_with_downscale() is removed from 5.0. Use image_util_decode_create() instead.");
 
@@ -676,14 +677,10 @@ int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspac
        image_util_retvm_if(!_is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "Not supported format");
 
        err = mm_util_decode_from_jpeg_file(path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale], &image);
-       image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "mm_util_decode_from_jpeg_file failed. (%d)", err);
+       image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "image_util_decode_jpeg_with_downscale failed. (%d)", err);
 
-       err = mm_image_get_image(image, &image_width, &image_height, NULL, image_buffer, &image_size);
-       if (width)
-               *width = image_width;
-       if (height)
-               *height = image_height;
-       *size = image_size;
+       err = __image_util_get_image(image, width, height, image_buffer, size);
+       mm_image_destroy_image(image);
 
        return _image_error_capi(err);
 }
@@ -692,9 +689,6 @@ int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_
 {
        int err = MM_UTIL_ERROR_NONE;
        mm_util_image_h image = NULL;
-       unsigned int image_width = 0;
-       unsigned int image_height = 0;
-       size_t image_size = 0;
 
        image_util_warning("DEPRECATION WARNING: image_util_decode_jpeg_from_memory_with_downscale() is removed from 5.0. Use image_util_decode_create() instead.");
 
@@ -707,14 +701,10 @@ int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_
 
        err = mm_util_decode_from_jpeg_memory((void  *)jpeg_buffer, (size_t)jpeg_size,
                                        TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale], &image);
-       image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "mm_util_decode_from_jpeg_file failed. (%d)", err);
+       image_util_retvm_if(err != MM_UTIL_ERROR_NONE, _image_error_capi(err), "image_util_decode_jpeg_from_memory_with_downscale failed. (%d)", err);
 
-       err = mm_image_get_image(image, &image_width, &image_height, NULL, image_buffer, &image_size);
-       if (width)
-               *width = image_width;
-       if (height)
-               *height = image_height;
-       *size = image_size;
+       err = __image_util_get_image(image, width, height, image_buffer, size);
+       mm_image_destroy_image(image);
 
        return _image_error_capi(err);
 }