Fix memory leak for the image_util_frame_h by using image_util_frame_create() 40/152940/5
authorJiyong Min <jiyong.min@samsung.com>
Wed, 27 Sep 2017 10:45:17 +0000 (19:45 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Thu, 28 Sep 2017 05:22:36 +0000 (14:22 +0900)
(fix coverity issue)

Change-Id: Iec223cb598204c8a0cddd3e6e8186a0143fc5e0d
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
decode-test/image_util_decode_encode_testsuite.c
packaging/capi-media-image-util.spec
src/image_util_internal.c
test/image_util_test.c

index 07ed864..c93f6ee 100755 (executable)
@@ -146,7 +146,7 @@ static gboolean _read_file(char *file_name, void **data, unsigned long long *dat
                        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");
@@ -383,9 +383,9 @@ void _print_help(int argc, char *argv[])
 
        fprintf(stderr, "\t[usage]\n");
        fprintf(stderr, "\t\t1. decode & encode : %s ", argv[0]);
-       for (i = 0; i < LAST_DECODE_TEST; i++) {
+       for (i = 0; i <= LAST_DECODE_TEST; i++) {
                fprintf(stderr, "%s", TEST_CMD[i]);
-               if (i != LAST_DECODE_TEST - 1)
+               if (i != LAST_DECODE_TEST)
                        fprintf(stderr, "/");
        }
        fprintf(stderr, " filepath encode_image_type\n");
index 5a58bf2..bda43e0 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-image-util
 Summary:    A Image Utility library in Tizen Native API
-Version:    0.1.28
+Version:    0.1.29
 Release:    2
 Group:      Multimedia/API
 License:    Apache-2.0
index 48a6698..2bc97e3 100755 (executable)
@@ -195,6 +195,8 @@ void image_util_frame_destroy(image_util_frame_h frame_h)
 
        frame_s *frame = (frame_s *)frame_h;
        mm_util_gif_image_destory(frame->frame_h);
+
+       IMAGE_UTIL_SAFE_FREE(frame);
 }
 
 int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h frame_h)
index 2064eb7..5f8d8bd 100755 (executable)
@@ -255,15 +255,17 @@ create_media_packet()
                                src = malloc(size);
                                if (src == NULL) {
                                        g_printf("\tmemory allocation failed\n");
+                                       fclose(fp);
                                        return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
                                }
-                               if (fread(src, 1, (int)size, fp)) {
+                               if (fread(src, 1, (int)size, fp) == size) {
                                        g_printf("#Success# fread\n");
                                        memcpy(ptr, src, (int)size);
                                        g_printf("memcpy\n");
                                } else {
                                        g_printf("#Error# fread\n");
                                }
+                               fclose(fp);
                        }
                }
        } else {
@@ -584,8 +586,6 @@ int main(int argc, char **argv)
                goto Exit;
        }
 
-       bool hardware_acceleration = FALSE;
-
        ret = create_media_packet();
        if (ret == MEDIA_PACKET_ERROR_NONE) {
                g_printf("Success - Create_media_packet\n");
@@ -594,7 +594,7 @@ int main(int argc, char **argv)
                goto Exit;
        }
 
-       ret = image_util_transform_set_hardware_acceleration(g_handle, hardware_acceleration);
+       ret = image_util_transform_set_hardware_acceleration(g_handle, FALSE);
        if (ret != IMAGE_UTIL_ERROR_NONE) {
                g_printf("[%d]Error image_util_transform_set_hardware_acceleration condition [%d]\n", __LINE__, ret);
                goto Exit;