[0.3.140] Fix memory leak when set player_set_media_packet_video_frame_decoded_cb() 84/251184/5 accepted/tizen/unified/20210113.121054 submit/tizen/20210112.010247
authorGilbok Lee <gilbok.lee@samsung.com>
Mon, 11 Jan 2021 05:28:39 +0000 (14:28 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Mon, 11 Jan 2021 08:44:01 +0000 (17:44 +0900)
- When tsurf_pool was not used, tsurf_data was not released

Change-Id: Ibd9f8b0cbb20eaf7e2b96663a4e695b53a1e5781

packaging/capi-media-player.spec
src/player.c

index 92c7b6e..f67fb1d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-player
 Summary:    A Media Player API
-Version:    0.3.139
+Version:    0.3.140
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index edcd82b..70a2c00 100644 (file)
@@ -920,22 +920,23 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s *cb_info, _
                        bo[i] = tbm_bo_import_fd(cb_info->bufmgr, recv_data->tfd[i]);
                }
 
-               tsurf_data = g_new(player_tsurf_info_s, 1);
-               if (!tsurf_data) {
-                       LOGE("failed to alloc tsurf info");
-                       goto ERROR;
-               }
-               memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
-
                tsurf = tbm_surface_internal_create_with_bos(&sinfo, bo, bo_num);
                if (!tsurf) {
                        LOGE("failed to create tbm surface");
-                       g_free(tsurf_data);
                        goto ERROR;
                }
-               memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
-               tsurf_data->tsurf = tsurf;
+
                if (cb_info->use_tsurf_pool) {
+                       tsurf_data = g_try_new(player_tsurf_info_s, 1);
+                       if (!tsurf_data) {
+                               LOGE("failed to alloc tsurf info");
+                               goto ERROR;
+                       }
+                       memset(tsurf_data->key, INVALID_DEFAULT_VALUE, sizeof(tsurf_data->key));
+
+                       memcpy(tsurf_data->key, key, sizeof(tsurf_data->key));
+                       tsurf_data->tsurf = tsurf;
+
                        g_mutex_lock(&cb_info->data_mutex);
                        cb_info->tsurf_list = g_list_append(cb_info->tsurf_list, tsurf_data);
                        LOGD("key %d is added to the pool", key[0]);
@@ -982,7 +983,7 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s *cb_info, _
                }
        }
 
-       fin_data = g_new0(_media_pkt_video_fin_data, 1);
+       fin_data = g_try_new0(_media_pkt_video_fin_data, 1);
        if (!fin_data) {
                LOGE("failed to alloc fin_data");
                goto ERROR;
@@ -1033,6 +1034,8 @@ static void __media_packet_video_frame_cb_handler(callback_cb_info_s *cb_info, _
 ERROR:
        if (pkt)
                media_packet_destroy(pkt);
+       else if (!tsurf_data && tsurf)
+               tbm_surface_destroy(tsurf);
 
        if (fin_data)
                g_free(fin_data);