Fix coverity issues
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
index 608b44c..16fb4fd 100755 (executable)
@@ -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) {
@@ -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);