Fix memory leak when error happened 73/279173/5 accepted/tizen_6.0_unified tizen_6.0 accepted/tizen/6.0/unified/20220805.131707 submit/tizen_6.0/20220804.015934
authorGilbok Lee <gilbok.lee@samsung.com>
Wed, 3 Aug 2022 06:23:44 +0000 (15:23 +0900)
committerGilbok Lee <gilbok.lee@samsung.com>
Wed, 3 Aug 2022 07:44:00 +0000 (16:44 +0900)
[Version] 0.1.36
[Issue Type] Fix memory leak

Change-Id: I4eccf66004398a307369d6c61e552b788f05892f

packaging/capi-mediademuxer.spec
src/port_gst/mediademuxer_port_gst.c

index 6680dba..cad47ff 100644 (file)
@@ -1,7 +1,7 @@
 Name:       capi-mediademuxer
 Summary:    A Media Demuxer library in Tizen Native API
-Version:    0.1.35
-Release:    1
+Version:    0.1.36
+Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index 7f28818..d5122ed 100644 (file)
@@ -974,7 +974,7 @@ static int _gst_create_pipeline(mdgst_handle_t *gst_handle, char *uri)
        gst_object_unref(GST_OBJECT(bus));
 
        /* set pipeline state to PAUSED */
-       MEDIADEMUXER_SET_STATE(gst_handle->pipeline, GST_STATE_PAUSED, ERROR);
+       MEDIADEMUXER_SET_STATE(gst_handle->pipeline, GST_STATE_PAUSED, ERROR_STATE_CHANGE);
 
        if (gst_element_get_state(gst_handle->pipeline, &element_state, &element_pending_state, 1 * GST_SECOND)
                == GST_STATE_CHANGE_FAILURE) {
@@ -983,18 +983,38 @@ static int _gst_create_pipeline(mdgst_handle_t *gst_handle, char *uri)
                        gst_element_state_get_name(element_state),
                        gst_element_state_get_name(element_pending_state));
                ret = MD_ERROR;
-               goto ERROR;
+               goto ERROR_STATE_CHANGE;
        }
 
-       if (gst_handle->is_prepared != true) {
+       if (!gst_handle->is_prepared) {
                MD_E("Error occure");
                ret = MD_ERROR;
-               goto ERROR;
+               goto ERROR_STATE_CHANGE;
        }
 
        MEDIADEMUXER_FLEAVE();
        return ret;
+
 ERROR:
+       if (gst_handle->filesrc)
+               gst_object_unref(gst_handle->filesrc);
+
+       if (gst_handle->typefind)
+               gst_object_unref(gst_handle->typefind);
+
+       if (gst_handle->fakesink)
+               gst_object_unref(gst_handle->fakesink);
+
+ERROR_STATE_CHANGE:
+       if (gst_handle->pipeline) {
+               gst_object_unref(gst_handle->pipeline);
+               gst_handle->pipeline = NULL;
+       }
+
+       gst_handle->filesrc = NULL;
+       gst_handle->typefind = NULL;
+       gst_handle->fakesink = NULL;
+
        MEDIADEMUXER_FLEAVE();
        return ret;
 }