Modify to free memory encoded to bmp and add to check return value from fread 33/152933/7 accepted/tizen/unified/20170929.081607 submit/tizen/20170928.093256
authorJiyong Min <jiyong.min@samsung.com>
Wed, 27 Sep 2017 10:36:17 +0000 (19:36 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Thu, 28 Sep 2017 05:18:25 +0000 (14:18 +0900)
(fix coverity issue)

Change-Id: Id380453efa6a148e900aba38eff78045ac2c9840
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
bmp/mm_util_bmp.c
imgp/mm_util_imgp.c
imgp/test/mm_util_imgp_testsuite.c
jpeg/test/mm_util_jpeg_testsuite.c
packaging/libmm-utility.spec
png/test/mm_util_png_testsuite.c

index 9d7a628..946b310 100755 (executable)
@@ -285,7 +285,7 @@ int mm_util_encode_bmp_to_memory(mm_util_bmp_data *encoded, void **buffer, size_
        if (bmp_save2(bmp, buffer, size) == false) {
                mm_util_error("Saving bmp was failed.");
                bmp_destroy(bmp);
-               BMP_SAFE_FREE(buffer);
+               BMP_SAFE_FREE(*buffer);
                *size = 0;
                return MM_UTIL_ERROR_INVALID_OPERATION;
        }
index 086fcc5..82cd5e8 100755 (executable)
@@ -894,7 +894,11 @@ gpointer _mm_util_thread_repeate(gpointer data)
                end_time = g_get_monotonic_time() + 1 * G_TIME_SPAN_SECOND;
                mm_util_debug("waiting...");
                g_mutex_lock(&(handle->thread_mutex));
-               g_cond_wait_until(&(handle->thread_cond), &(handle->thread_mutex), end_time);
+               if (!g_cond_wait_until(&(handle->thread_cond), &(handle->thread_mutex), end_time)) {
+                       mm_util_debug("exit loop");
+                       g_mutex_unlock(&(handle->thread_mutex));
+                       break;
+               }
                mm_util_debug("<=== get run transform thread signal");
                g_mutex_unlock(&(handle->thread_mutex));
 
@@ -1331,7 +1335,8 @@ int mm_util_create(mm_util_imgp_h *imgp_handle)
        mm_util_s *handle = calloc(1, sizeof(mm_util_s));
        if (!handle) {
                mm_util_error("[ERROR] - _handle");
-               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               TTRACE_END();
+               return MM_UTIL_ERROR_INVALID_OPERATION;
        }
 
        ret = __mm_util_handle_init(handle);
@@ -1339,12 +1344,13 @@ int mm_util_create(mm_util_imgp_h *imgp_handle)
                mm_util_error("_mm_util_handle_init failed");
                IMGP_FREE(handle);
                TTRACE_END();
-               return MM_UTIL_ERROR_INVALID_PARAMETER;
+               return ret;
        }
 
        ret = __mm_util_create_thread(handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("ERROR - Create thread");
+               IMGP_FREE(handle);
                TTRACE_END();
                return ret;
        } else {
index be44e20..ef4f84f 100755 (executable)
@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
                        goto TEST_FAIL;
                }
 
-               if (fread(src, 1, (int)src_size, fp))
+               if (fread(src, 1, (int)src_size, fp) == src_size)
                        mm_util_debug("#Success# fread");
                else
                        mm_util_error("#Error# fread");
index 75cf6fc..29aea88 100755 (executable)
@@ -72,7 +72,7 @@ static int _read_file(char *file_name, void **data, unsigned int *data_size)
                        fp = NULL;
                        return FALSE;
                } else {
-                       if (fread(*data, 1, file_size, fp)) {
+                       if (fread(*data, 1, file_size, fp) == (size_t)file_size) {
                                fprintf(stderr, "#Success# fread\n");
                        } else {
                                fprintf(stderr, "#Error# fread\n");
index ef92872..ef1cdc4 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.41
+Version:    0.42
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 1a708cc..dc73899 100755 (executable)
@@ -67,7 +67,7 @@ static int _read_file(char *file_name, void **data, int *data_size)
                        fp = NULL;
                        return FALSE;
                } else {
-                       if (fread(*data, 1, file_size, fp)) {
+                       if (fread(*data, 1, file_size, fp) == (size_t)file_size) {
                                fprintf(stderr, "\t#Success# fread\n");
                        } else {
                                fprintf(stderr, "\t#Error# fread\n");