Fixed mem leak 54/148654/2
authorJaechan Lee <jaechan3.lee@samsung.com>
Mon, 28 Aug 2017 07:59:45 +0000 (16:59 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Fri, 8 Sep 2017 08:21:36 +0000 (17:21 +0900)
[Problem] Memory is leaked during playing mp3 files.
[Cause & Measure] Cause : caps should be freed by calling gst_caps_unref.
Measure : Fixed memory leak

[Developer] JaeChan Lee
(cherry picked from commit de35c90bb00c9609c36d6435b0667e0741d8b862)

Change-Id: I5ce39cb9ebf2d391c3838962430d828841329ae3

src/mm_player_capture.c
src/mm_player_priv.c

index 514ab7a..7f8c134 100644 (file)
@@ -166,6 +166,8 @@ _mmplayer_do_video_capture(MMHandleType hplayer)
                        return ret;
                } else {
                        LOGW("invalid state(%d) to capture", player->state);
+                       gst_object_unref(GST_OBJECT(pad));
+                       pad = NULL;
                        return MM_ERROR_PLAYER_INVALID_STATE;
                }
        }
index 69a168d..a700208 100644 (file)
@@ -2187,6 +2187,9 @@ NEW_ELEMENT:
                MMPLAYER_ELEMENT_SET_STATE(new_element, GST_STATE_PLAYING);
        }
 
+       if (caps)
+               gst_caps_unref(caps);
+
        MMPLAYER_FLEAVE();
 
        return;
@@ -2201,7 +2204,7 @@ ERROR:
                gst_object_unref(GST_OBJECT(sinkpad));
 
        if (caps)
-               gst_object_unref(GST_OBJECT(caps));
+               gst_caps_unref(caps);
 
        /* FIXIT : how to inform this error to MSL ????? */
        /* FIXIT : I think we'd better to use g_idle_add() to destroy pipeline and
@@ -2242,7 +2245,7 @@ __mmplayer_gst_selector_event_probe(GstPad * pad, GstPadProbeInfo * info, gpoint
        caps = gst_pad_query_caps(pad, NULL);
        if (!caps) {
                LOGE("failed to get caps from pad[%s:%s]", GST_DEBUG_PAD_NAME(pad));
-               goto ERROR;
+               return ret;
        }
 
        str = gst_caps_get_structure(caps, 0);
@@ -2556,7 +2559,7 @@ __mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
 
                if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
                        __mmplayer_gst_decode_callback(elem, pad, player);
-                       return;
+                       goto DONE;
                }
 
                LOGD("video selector \n");
@@ -2569,7 +2572,7 @@ __mmplayer_gst_decode_pad_added(GstElement *elem, GstPad *pad, gpointer data)
 
                        if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
                                __mmplayer_gst_decode_callback(elem, pad, player);
-                               return;
+                               goto DONE;
                        }
 
                        LOGD("audio selector \n");
@@ -2741,14 +2744,17 @@ __mmplayer_gst_deinterleave_pad_added(GstElement *elem, GstPad *pad, gpointer da
 
        GstPad* srcpad = NULL;
        GstPad* sinkpad = NULL;
+       GstCaps* caps = NULL;
        gchar* caps_str = NULL;
 
        MMPLAYER_FENTER();
        MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);
 
-       caps_str = gst_caps_to_string(gst_pad_get_current_caps(pad));
+       caps = gst_pad_get_current_caps(pad);
+       caps_str = gst_caps_to_string(caps);
        LOGD("deinterleave new caps : %s\n", caps_str);
        MMPLAYER_FREEIF(caps_str);
+       gst_caps_unref(caps);
 
        if ((queue = __mmplayer_element_create_and_link(player, pad, "queue")) == NULL) {
                LOGE("ERROR : queue create error\n");
@@ -2837,6 +2843,7 @@ __mmplayer_gst_deinterleave_no_more_pads(GstElement *elem, gpointer data)
                                MMPLAYER_LOG_GST_CAPS_TYPE(caps);
 
                                __mmplayer_set_audio_attrs(player, caps);
+                               gst_caps_unref(caps);
                        }
                        MMPLAYER_FREEIF(change_pad_name);
                }
@@ -4333,7 +4340,7 @@ __mmplayer_gst_audio_deinterleave_pad_added(GstElement *elem, GstPad *pad, gpoin
                (gpointer)player);
 
        MMPLAYER_FLEAVE();
-       return ;
+       return;
 
 ERROR:
        LOGE("__mmplayer_gst_audio_deinterleave_pad_added ERROR\n");
@@ -6184,7 +6191,7 @@ __mmplayer_gst_create_pipeline(mm_player_t* player)
                                g_object_set(G_OBJECT(element), "timeout", http_timeout, NULL);
                                g_object_set(G_OBJECT(element), "blocksize", (unsigned long)(64*1024), NULL);
 
-                               /* check if prosy is vailid or not */
+                               /* check if proxy is valid or not */
                                if (util_check_valid_url(proxy))
                                        g_object_set(G_OBJECT(element), "proxy", proxy, NULL);
                                /* parsing cookies */
@@ -7209,6 +7216,8 @@ int __gst_pause(mm_player_t* player, gboolean async)
                                                                ret = __gst_handle_library_error(player, error->code);
                                                        else if (error->domain == GST_CORE_ERROR)
                                                                ret = __gst_handle_core_error(player, error->code);
+
+                                                       g_error_free(error);
                                                }
                                                player->msg_posted = TRUE;
                                        }
@@ -9058,8 +9067,6 @@ _mmplayer_get_volume(MMHandleType hplayer, MMPlayerVolumeType* volume)
        return MM_ERROR_NONE;
 }
 
-
-
 int
 _mmplayer_set_mute(MMHandleType hplayer, int mute)
 {
@@ -9953,7 +9960,7 @@ GstCaps *caps, gpointer data)
        MMPLAYER_FREEIF(player->type);
        player->type = gst_caps_to_string(caps);
        if (player->type)
-               LOGD("meida type %s found, probability %d%% / %d\n", player->type, probability, gst_caps_get_size(caps));
+               LOGD("media type %s found, probability %d%% / %d\n", player->type, probability, gst_caps_get_size(caps));
 
        if ((!MMPLAYER_IS_RTSP_STREAMING(player)) &&
                (g_strrstr(player->type, "audio/x-raw-int"))) {
@@ -11320,6 +11327,7 @@ gpointer data)
                LOGD("pad removed caps : %s from %s", caps_str, GST_ELEMENT_NAME(elem));
 
                MMPLAYER_FREEIF(caps_str);
+               gst_caps_unref(caps);
        }
 }
 
@@ -11821,13 +11829,8 @@ __mmplayer_handle_streaming_error(mm_player_t* player, GstMessage * message)
        MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
        MMPLAYER_RETURN_VAL_IF_FAIL(message, FALSE);
 
-       s = malloc(sizeof(GstStructure));
-       if (s == NULL) {
-               LOGE("failed to alloc data.");
-               return FALSE;
-       }
+       s = gst_structure_copy(gst_message_get_structure(message));
 
-       memcpy(s, gst_message_get_structure(message), sizeof(GstStructure));
 
        if (!gst_structure_get_uint(s, "error_id", &error_id))
                error_id = MMPLAYER_STREAMING_ERROR_NONE;
@@ -11970,7 +11973,7 @@ __mmplayer_handle_streaming_error(mm_player_t* player, GstMessage * message)
                break;
        default:
                {
-                       MMPLAYER_FREEIF(s);
+                       gst_structure_free(s);
                        return MM_ERROR_PLAYER_STREAMING_FAIL;
                }
        }
@@ -11995,7 +11998,7 @@ __mmplayer_handle_streaming_error(mm_player_t* player, GstMessage * message)
        } else
                LOGD("skip error post because it's sent already.\n");
 
-       MMPLAYER_FREEIF(s);
+       gst_structure_free(s);
        MMPLAYER_FLEAVE();
        g_free(error_string);
 
@@ -12008,7 +12011,6 @@ __mmplayer_handle_eos_delay(mm_player_t* player, int delay_in_ms)
 {
        MMPLAYER_RETURN_IF_FAIL(player);
 
-
        /* post now if delay is zero */
        if (delay_in_ms == 0 || player->set_mode.pcm_extraction) {
                LOGD("eos delay is zero. posting EOS now\n");