From 13bdd3392830a3270328faa0abd31086902ae03b Mon Sep 17 00:00:00 2001 From: Haejeong Kim Date: Wed, 11 Oct 2017 17:41:29 +0900 Subject: [PATCH] Svace issue fix Change-Id: Iabdaa768f95515c3eb990006e0e77d6802e6611c --- test/image_util_test.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/image_util_test.c b/test/image_util_test.c index bfe536a..9bd1148 100755 --- a/test/image_util_test.c +++ b/test/image_util_test.c @@ -143,6 +143,7 @@ bool test_transform_completed_cb(media_packet_h *packet, image_util_error_e erro if (media_packet_get_format(*packet, &dst_fmt) != MEDIA_PACKET_ERROR_NONE) { g_printf("Imedia_packet_get_format"); _signal(); + IMAGE_UTIL_SAFE_FREE(output_fmt); return FALSE; } @@ -198,8 +199,8 @@ create_media_packet() { int ret = 0; media_format_h fmt; - void *src; - void *ptr; + void *src = NULL; + void *ptr = NULL; if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) { if (media_format_set_video_mime(fmt, _image_util_mapping_imgp_format_to_mime(g_format)) != MEDIA_FORMAT_ERROR_NONE) { media_format_unref(fmt); @@ -241,11 +242,6 @@ create_media_packet() g_printf("Success - media_packet_create_alloc\n"); uint64_t size = 0; if (media_packet_get_buffer_size(g_src, &size) == MEDIA_PACKET_ERROR_NONE) { - ptr = malloc(size); - if (ptr == NULL) { - g_printf("\tmemory allocation failed\n"); - return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - } if (media_packet_get_buffer_data_ptr(g_src, &ptr) == MEDIA_PACKET_ERROR_NONE) { FILE *fp = fopen(g_path, "r"); if (fp == NULL) { @@ -480,6 +476,10 @@ static void interpret_set_image_cmd(char *cmd) } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_PATH) { IMAGE_UTIL_SAFE_FREE(g_path); g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *)); + if (g_path == NULL) { + g_printf("memory allocation fail. \n"); + return; + } memset(g_path, 0x00, MAX_STRING_LEN); snprintf(g_path, MAX_STRING_LEN, "%s", cmd); g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; @@ -572,6 +572,11 @@ int main(int argc, char **argv) g_handle = NULL; g_src = NULL; g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *)); + if (g_path == NULL) { + g_printf("memory allocation fail. \n"); + return ret; + } + memset(g_path, 0x00, MAX_STRING_LEN); snprintf(g_path, MAX_STRING_LEN, "%s", argv[1]); g_width = atoi(argv[2]); -- 2.7.4