Fix coverity issues
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
index 85636ff..16fb4fd 100755 (executable)
@@ -518,7 +518,7 @@ static int __media_svc_resize_artwork(const char *path, const char *img_format)
        unsigned int height = 0;
        unsigned int resized_width = 0;
        unsigned int resized_height = 0;
-       mm_util_img_codec_type img_type = IMG_CODEC_NONE;
+       mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
 
        if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
                media_svc_debug("type [jpeg]");
@@ -953,17 +953,22 @@ int image_360_check(char *path)
        FILE *fp = NULL;
        long app1_size = 0;
        int size = 1;
-       unsigned char exif_header[4];
-       unsigned char exif_app1[2];
-       unsigned char exif_app1_xmp[2];
+       unsigned char exif_header[4] = {0, };
+       unsigned char exif_app1[2] = {0, };
+       unsigned char exif_app1_xmp[2] = {0, };
        long exif_app1_xmp_size = 0;
-       unsigned char exif_app1_xmp_t[2];
+       unsigned char exif_app1_xmp_t[2] = {0, };
        char *xmp_data = NULL;
        int size1 = 0;
        int size2 = 0;
        int fdata = 0;
        int temp = 0;
 
+       memset(exif_header, 0x00, sizeof(exif_header));
+       memset(exif_app1, 0x00, sizeof(exif_app1));
+       memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
+       memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
+
        fp = fopen(path, "rb");
        if (fp == NULL)
                goto ERROR;
@@ -1001,9 +1006,10 @@ int image_360_check(char *path)
 
                        exif_app1_xmp_size = size1 * 256 + size2 - 2;
 
-                       xmp_data = (char *)malloc(exif_app1_xmp_size);
-                       if (xmp_data != NULL) {
+                       if (exif_app1_xmp_size > 0) {
+                               xmp_data = (char *)malloc(exif_app1_xmp_size);
                                memset(xmp_data, 0x0, exif_app1_xmp_size);
+
                                ptr = xmp_data;
 
                                while (exif_app1_xmp_size >= 0) {
@@ -1027,7 +1033,7 @@ int image_360_check(char *path)
 
                                SAFE_FREE(xmp_data);
                        } else {
-                               media_svc_error("malloc failed");
+                               media_svc_error("invalid exif_app1_xmp_size [%ld]", exif_app1_xmp_size);
                        }
 
                        if (fp) {
@@ -1233,7 +1239,7 @@ GET_WIDTH_HEIGHT:
                /*Get image width, height*/
                unsigned int img_width = 0;
                unsigned int img_height = 0;
-               mm_util_img_codec_type img_type = IMG_CODEC_NONE;
+               mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
 
                mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
                if (content_info->media_meta.width == 0)
@@ -1447,7 +1453,6 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
                                        SAFE_FREE(time_info);
                                } else {
                                        media_svc_error("memory allocation error");
-                                       ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
                                }
                        } else {
                                content_info->media_meta.recorded_date = g_strdup(p);
@@ -1804,7 +1809,7 @@ int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_leng
        unsigned int origin_h = 0;
        unsigned int thumb_w = THUMB_WIDTH;
        unsigned int thumb_h = THUMB_HEIGHT;
-       mm_util_img_codec_type image_type = IMG_CODEC_NONE;
+       mm_util_img_codec_type image_type = IMG_CODEC_UNKNOWN_TYPE;
 
        if (path == NULL || thumb_path == NULL) {
                media_svc_error("Invalid parameter");
@@ -1829,7 +1834,7 @@ int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_leng
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       media_svc_sec_debug("Path : %s", path);
+       media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
 
        //1. make hash path
        ret = _media_svc_get_thumbnail_path(store_type, media_type, thumb_path, path, THUMB_EXT, uid);