Fix crash during destroy(due to double free)
[platform/core/api/video-util.git] / test / video_util_test.c
index 6895ba0..fe170bb 100644 (file)
@@ -68,8 +68,11 @@ typedef struct {
        unsigned long duration;
 } test_util_s;
 
-static void display_sub_basic();
+test_util_s *_util_s;
+
 
+static void display_sub_basic();
+void _video_util_start_transcoding(test_util_s *util_s);
 
 void _quit_program(void)
 {
@@ -144,14 +147,16 @@ void _transcode_completed_cb(video_util_error_e error, void *user_data)
 
        test_util_s *_util_s = (test_util_s *)user_data;
 
+       if (!_util_s) {
+               LOGE("completed_cb user data is NULL");
+               return;
+       }
+
        LOGI("transcode_completed_cb============= [%2d / %2d][%d]\n", _util_s->idx, make_video_cnt, error);
        printf("transcode_completed_cb============= [%2d / %2d][%d]\n", _util_s->idx, make_video_cnt, error);
 
        if (_util_s->idx == (make_video_cnt - 1)) {
                LOGI("End trascoding");
-               video_util_destroy(_util_s->video_h);
-               _util_s->video_h = NULL;
-               video_h = NULL;
                return;
        }
 
@@ -160,7 +165,7 @@ void _transcode_completed_cb(video_util_error_e error, void *user_data)
        _util_s->idx = idx;
        _util_s->start_time = ntn_start_position;
 
-       _video_util_start_transcoding((test_util_s *)_util_s);
+       _video_util_start_transcoding(_util_s);
 
        return;
 }
@@ -236,6 +241,8 @@ void _video_util_start_transcoding(test_util_s *util_s)
                LOGE("video_util_start_transcoding is failed (%d)", ret);
                return;
        }
+
+       return;
 }
 
 void _reset_var()
@@ -263,7 +270,6 @@ void _reset_var()
 static void input_filename(char *filename)
 {
        int len = strlen(filename);
-       int i = 0;
        int ret = VIDEO_UTIL_ERROR_NONE;
 
        if (len < 0 || len > MAX_STRING_LEN) {
@@ -313,10 +319,13 @@ void _interpret_main_menu(char *cmd)
                if (strncmp(cmd, "a", 1) == 0) {
                        g_menu_state = CURRENT_STATUS_FILENAME;
                } else if (strncmp(cmd, "s", 1) == 0) {
+                       if (!_util_s) {
+                               _util_s = (test_util_s *)calloc(1, sizeof(test_util_s));
+                               LOGE("_util_s malloc");
+                       }
 
-                       test_util_s *_util_s = (test_util_s *)calloc(1, sizeof(test_util_s));
                        if (!_util_s) {
-                               g_print("test util calloc failed");
+                               LOGE("test util calloc failed");
                                return;
                        }
 
@@ -348,6 +357,19 @@ void _interpret_main_menu(char *cmd)
                        g_menu_state = CURRENT_STATUS_SET_OUTFILENAME;
                } else if (strncmp(cmd, "q", 1) == 0) {
                        _quit_program();
+               } else if (strncmp(cmd, "d", 1) == 0) {
+                       int ret = VIDEO_UTIL_ERROR_NONE;
+                       if (!video_h) {
+                               g_print("video_util handle is NULL, please set format after create");
+                               return;;
+                       }
+                       ret = video_util_destroy(video_h);
+                       if (ret != VIDEO_UTIL_ERROR_NONE) {
+                               g_print("video_util_cancel_transcoding is failed (%d)", ret);
+                               return;
+                       }
+                       free(_util_s);
+                       _util_s = NULL;
                } else {
                        g_print("unknown menu \n");
                }
@@ -572,7 +594,6 @@ static void interpret(char *cmd)
                }
        case CURRENT_STATUS_SET_TIME:
                {
-                       int ret = VIDEO_UTIL_ERROR_NONE;
                        int value = atoi(cmd);
                        static int set_time_cnt = 0;
 
@@ -627,7 +648,8 @@ static void display_sub_basic()
        g_print("vf. Set video fps\n");
        g_print(" t. Set start/duration time \t");
        g_print(" o. Set output filename\t");
-       g_print(" q. quite test suite\t");
+       g_print(" q. quite test suite\t\n");
+       g_print(" d. Destroy\t");
        g_print("\n");
        g_print("=========================================================================================\n");
 }