From 14f2335c30d111383e20a554eb3cf2c376076358 Mon Sep 17 00:00:00 2001 From: Gilbok Lee Date: Wed, 3 Aug 2022 15:23:44 +0900 Subject: [PATCH] Fix memory leak when error happened [Version] 0.1.36 [Issue Type] Fix memory leak Change-Id: I4eccf66004398a307369d6c61e552b788f05892f --- packaging/capi-mediademuxer.spec | 4 ++-- src/port_gst/mediademuxer_port_gst.c | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packaging/capi-mediademuxer.spec b/packaging/capi-mediademuxer.spec index 6680dba..cad47ff 100644 --- a/packaging/capi-mediademuxer.spec +++ b/packaging/capi-mediademuxer.spec @@ -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 diff --git a/src/port_gst/mediademuxer_port_gst.c b/src/port_gst/mediademuxer_port_gst.c index 7f28818..d5122ed 100644 --- a/src/port_gst/mediademuxer_port_gst.c +++ b/src/port_gst/mediademuxer_port_gst.c @@ -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; } -- 2.7.4