[0.6.104] Fix memory leak 68/200868/3
authorGilbok Lee <gilbok.lee@samsung.com>
Tue, 5 Mar 2019 08:03:04 +0000 (17:03 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Tue, 5 Mar 2019 08:22:24 +0000 (17:22 +0900)
Change-Id: Ic8c63b3a7226e25ee9195135439a092d22d3502c

packaging/libmm-player.spec
src/mm_player_priv.c

index 360535782330791747fc3cf4537a53570ac3ac18..e7c50a9c9594f83656486ba8cf03886f54759d24 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-player
 Summary:    Multimedia Framework Player Library
-Version:    0.6.103
+Version:    0.6.104
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 0b00d3d59420bb2dfa3b65b80dd9c4afe5a70d14..8670197c36a79e400ae17b6d8f82913da62cd1c1 100644 (file)
@@ -462,12 +462,14 @@ _mmplayer_update_content_attrs(mm_player_t* player, enum content_attr_flag flag)
                                        }
 
                                        has_video_attrs = TRUE;
-                               } else
+                               } else {
                                        LOGD("no negitiated caps from videosink");
-                               gst_object_unref(pad);
+                               }
+                               gst_object_unref(GST_OBJECT(pad));
                                pad = NULL;
-                       } else
+                       } else {
                                LOGD("no videosink sink pad");
+                       }
                }
        }
 
@@ -1242,6 +1244,8 @@ __mmplayer_gst_callback(GstMessage *msg, gpointer data)
                                        player->audio_stream_cb = NULL;
                                        player->audio_stream_cb_user_param = NULL;
 
+                                       gst_object_unref(GST_OBJECT(pad));
+
                                }
                        }
                        if ((player->audio_stream_render_cb_ex) && (!player->audio_stream_sink_sync))
@@ -2831,6 +2835,8 @@ __mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
                }
        }
 
+       gst_object_unref(GST_OBJECT(sinkpad));
+
        selector = player->pipeline->mainbin[elemId].gst;
        if (selector == NULL) {
                selector = gst_element_factory_make("input-selector", NULL);
@@ -3369,6 +3375,9 @@ __mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
                        gst_pad_remove_probe(srcpad, player->selector[MM_PLAYER_TRACK_TYPE_VIDEO].block_id);
                        player->selector[MM_PLAYER_TRACK_TYPE_VIDEO].block_id = 0;
                }
+
+               gst_object_unref(GST_OBJECT(srcpad));
+               srcpad = NULL;
        }
 
        if (audio_selector) {
@@ -3408,6 +3417,9 @@ __mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
                        }
                }
 
+               gst_object_unref(GST_OBJECT(srcpad));
+               srcpad = NULL;
+
                LOGD("Total audio tracks = %d \n", player->selector[MM_PLAYER_TRACK_TYPE_AUDIO].total_track_num);
 
                attrs = MMPLAYER_GET_ATTRS(player);
@@ -3440,11 +3452,6 @@ __mmplayer_gst_decode_no_more_pads(GstElement *elem, gpointer data)
        MMPLAYER_FLEAVE();
 
 ERROR:
-       if (srcpad) {
-               gst_object_unref(GST_OBJECT(srcpad));
-               srcpad = NULL;
-       }
-
        if (player->gapless.reconfigure) {
                player->gapless.reconfigure = FALSE;
                MMPLAYER_PLAYBACK_UNLOCK(player);
@@ -7013,8 +7020,12 @@ __mmplayer_gst_create_pipeline(mm_player_t* player)
                        } // else error
                } //  else error
 
-               if (mainbin[MMPLAYER_M_S_BUFFER].gst)
-                       __mmplayer_try_to_plug_decodebin(player, gst_element_get_static_pad(mainbin[MMPLAYER_M_S_BUFFER].gst, "src"), player->s_stream_caps);
+               if (mainbin[MMPLAYER_M_S_BUFFER].gst) {
+                       srcpad = gst_element_get_static_pad(mainbin[MMPLAYER_M_S_BUFFER].gst, "src");
+                       __mmplayer_try_to_plug_decodebin(player, srcpad, player->s_stream_caps);
+                       gst_object_unref(GST_OBJECT(srcpad));
+                       srcpad = NULL;
+               }
        }
 
        /* Note : check whether subtitle atrribute uri is set. If uri is set, then try to play subtitle file */
@@ -10603,6 +10614,7 @@ __mmplayer_try_to_plug_decodebin(mm_player_t* player, GstPad *srcpad, const GstC
        }
 
        gst_object_unref(GST_OBJECT(sinkpad));
+       gst_object_unref(GST_OBJECT(qsrcpad));
 
        mainbin[MMPLAYER_M_AUTOPLUG].id = MMPLAYER_M_AUTOPLUG;
        mainbin[MMPLAYER_M_AUTOPLUG].gst = decodebin;
@@ -10644,6 +10656,9 @@ ERROR:
        if (sinkpad)
                gst_object_unref(GST_OBJECT(sinkpad));
 
+       if (qsrcpad)
+               gst_object_unref(GST_OBJECT(qsrcpad));
+
        if (queue2) {
                /* NOTE : Trying to dispose element queue0, but it is in READY instead of the NULL state.
                 * You need to explicitly set elements to the NULL state before
@@ -12942,7 +12957,7 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                        NULL, NULL, NULL);
                {
                        LOGE("failed to set block pad(video)");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
                LOGW("pad is blocked(video)");
        } else {
@@ -12957,7 +12972,7 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
        if (!gst_element_remove_pad(player->pipeline->videobin[MMPLAYER_V_BIN].gst,
                GST_PAD_CAST(GST_GHOST_PAD(player->ghost_pad_for_videobin)))) {
                LOGE("failed to remove previous ghost_pad for videobin");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
 
        /* change state of videobin to NULL */
@@ -12965,14 +12980,14 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
        ret = gst_element_set_state(player->pipeline->videobin[MMPLAYER_V_BIN].gst, GST_STATE_NULL);
        if (ret != GST_STATE_CHANGE_SUCCESS) {
                LOGE("failed to change state of videobin to NULL");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
 
        /* unlink between decoder and videobin and remove previous videosink from videobin */
        gst_element_unlink(GST_ELEMENT(player->pipeline->mainbin[dec_index].gst), GST_ELEMENT(player->pipeline->videobin[MMPLAYER_V_BIN].gst));
        if (!gst_bin_remove(GST_BIN(player->pipeline->videobin[MMPLAYER_V_BIN].gst), GST_ELEMENT(player->pipeline->videobin[MMPLAYER_V_SINK].gst))) {
                LOGE("failed to remove former videosink from videobin");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
 
        __mmplayer_del_sink(player, player->pipeline->videobin[MMPLAYER_V_SINK].gst);
@@ -12981,8 +12996,7 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
        player->pipeline->videobin[MMPLAYER_V_SINK].gst = gst_element_factory_make(videosink_element, "videosink");
        if (!player->pipeline->videobin[MMPLAYER_V_SINK].gst) {
                LOGE("failed to create videosink element\n");
-               MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
        gst_bin_add(GST_BIN(player->pipeline->videobin[MMPLAYER_V_BIN].gst), GST_ELEMENT(player->pipeline->videobin[MMPLAYER_V_SINK].gst));
        __mmplayer_add_sink(player, player->pipeline->videobin[MMPLAYER_V_SINK].gst);
@@ -13000,24 +13014,21 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                        break;
                default:
                        LOGE("invalid type(%d) for changing display surface", surface_type);
-                       MMPLAYER_FLEAVE();
-                       return MM_ERROR_INVALID_ARGUMENT;
+                       goto ERROR;
                }
                if (mmf_attrs_commit(player->attrs)) {
                        LOGE("failed to commit");
-                       MMPLAYER_FLEAVE();
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
        } else {
                LOGE("player->attrs is null, failed to save attributes");
-               MMPLAYER_FLEAVE();
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
 
        /* update video param */
        if (MM_ERROR_NONE != _mmplayer_update_video_param(player, "update_all_param")) {
                LOGE("failed to update video param");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
 
        /* change state of videobin to READY */
@@ -13025,37 +13036,39 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
        ret = gst_element_set_state(player->pipeline->videobin[MMPLAYER_V_BIN].gst, GST_STATE_READY);
        if (ret != GST_STATE_CHANGE_SUCCESS) {
                LOGE("failed to change state of videobin to READY");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
 
        /* change ghostpad */
        sink_pad_videosink = gst_element_get_static_pad(GST_ELEMENT(player->pipeline->videobin[MMPLAYER_V_SINK].gst), "sink");
        if (!sink_pad_videosink) {
                LOGE("failed to get sink pad from videosink element");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
        player->ghost_pad_for_videobin = gst_ghost_pad_new("sink", sink_pad_videosink);
        if (!gst_pad_set_active(player->ghost_pad_for_videobin, TRUE)) {
                LOGE("failed to set active to ghost_pad");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
        if (FALSE == gst_element_add_pad(player->pipeline->videobin[MMPLAYER_V_BIN].gst, player->ghost_pad_for_videobin)) {
                LOGE("failed to change ghostpad for videobin");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
        gst_object_unref(sink_pad_videosink);
+       sink_pad_videosink = NULL;
 
        /* link decoder with videobin */
        sink_pad_videobin = gst_element_get_static_pad(GST_ELEMENT(player->pipeline->videobin[MMPLAYER_V_BIN].gst), "sink");
        if (!sink_pad_videobin) {
                LOGE("failed to get sink pad from videobin");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
        if (GST_PAD_LINK_OK != gst_pad_link(src_pad_dec, sink_pad_videobin)) {
                LOGE("failed to link");
-               return MM_ERROR_PLAYER_INTERNAL;
+               goto ERROR;
        }
        gst_object_unref(sink_pad_videobin);
+       sink_pad_videobin = NULL;
 
        /* clock setting for a new videosink plugin */
        /* NOTE : Below operation is needed, because a new videosink plugin doesn't have clock for basesink,
@@ -13080,10 +13093,11 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                                        GST_TIME_FORMAT, GST_TIME_ARGS(now), GST_TIME_ARGS(base_time));
                } else {
                        LOGE("failed to get clock of videosink after setting clock");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
-       } else
+       } else {
                LOGW("failed to get clock, maybe it is the time before first playing");
+       }
 
        if (!player->doing_seek && previous_state == MM_PLAYER_STATE_PLAYING) {
                /* change state of videobin to PAUSED */
@@ -13093,7 +13107,7 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                        LOGW("change state of videobin to PLAYING, ret(%d)", ret);
                } else {
                        LOGE("failed to change state of videobin to PLAYING");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
 
                /* release blocked and unref src pad of video decoder */
@@ -13114,7 +13128,7 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                        LOGW("change state of videobin to PAUSED, ret(%d)", ret);
                } else {
                        LOGE("failed to change state of videobin to PLAYING");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
 
                /* already skipped pad block */
@@ -13129,13 +13143,13 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                LOGD("do get/set position for new videosink plugin");
                if (__gst_get_position(player, MM_PLAYER_POS_FORMAT_TIME, &position)) {
                        LOGE("failed to get position");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
 #ifdef SINKCHANGE_WITH_ACCURATE_SEEK
                /* accurate seek */
                if (__gst_set_position(player, MM_PLAYER_POS_FORMAT_TIME, position, TRUE)) {
                        LOGE("failed to set position");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
 #else
                /* key unit seek */
@@ -13146,7 +13160,7 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
                                                        GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
                if (!ret) {
                        LOGE("failed to set position");
-                       return MM_ERROR_PLAYER_INTERNAL;
+                       goto ERROR;
                }
 #endif
        }
@@ -13158,6 +13172,17 @@ __mmplayer_do_change_videosink(mm_player_t* player, const int dec_index, const c
        MMPLAYER_FLEAVE();
 
        return MM_ERROR_NONE;
+
+ERROR:
+       if (src_pad_dec)
+               gst_object_unref(src_pad_dec);
+       if (sink_pad_videosink)
+               gst_object_unref(sink_pad_videosink);
+       if (sink_pad_videobin)
+               gst_object_unref(sink_pad_videobin);
+
+       MMPLAYER_FLEAVE();
+       return  MM_ERROR_PLAYER_INTERNAL;
 }
 
 
@@ -13946,6 +13971,8 @@ __mmplayer_release_dump_list(GList *dump_list)
                        if (dump_s->dump_pad) {
                                if (dump_s->probe_handle_id)
                                        gst_pad_remove_probe(dump_s->dump_pad, dump_s->probe_handle_id);
+
+                               gst_object_unref(GST_OBJECT(dump_s->dump_pad));
                        }
                        if (dump_s->dump_element_file) {
                                fclose(dump_s->dump_element_file);