From d1fb36a4395f15f2be77f0af3844169c7a95ebb5 Mon Sep 17 00:00:00 2001 From: Chien-Yu Chen Date: Tue, 11 Nov 2014 11:46:54 -0800 Subject: [PATCH] libgscaler: fix a mutex leak Bug: 11132653 Change-Id: I23ab470682d3483a7c2e5666c91db232e6c57a27 --- libgscaler/exynos_gsc_utils.h | 1 + libgscaler/exynos_gscaler.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libgscaler/exynos_gsc_utils.h b/libgscaler/exynos_gsc_utils.h index 8c0217f..8e5c49d 100644 --- a/libgscaler/exynos_gsc_utils.h +++ b/libgscaler/exynos_gsc_utils.h @@ -128,6 +128,7 @@ struct GSC_HANDLE { void *op_mutex; void *obj_mutex[NUM_OF_GSC_HW]; void *cur_obj_mutex; + bool destroy_cur_obj_mutex; bool flag_local_path; bool flag_exclusive_open; struct media_device *media0; diff --git a/libgscaler/exynos_gscaler.c b/libgscaler/exynos_gscaler.c index 360812b..0e7bb77 100644 --- a/libgscaler/exynos_gscaler.c +++ b/libgscaler/exynos_gscaler.c @@ -561,9 +561,14 @@ bool m_exynos_gsc_find_and_trylock_and_create( continue; } - if (gsc_handle->cur_obj_mutex) + /* Trade temporary object for one in the pool */ + if (gsc_handle->cur_obj_mutex) { exynos_mutex_unlock(gsc_handle->cur_obj_mutex); + if (gsc_handle->destroy_cur_obj_mutex) + exynos_mutex_destroy(gsc_handle->cur_obj_mutex); + } + gsc_handle->destroy_cur_obj_mutex = false; gsc_handle->cur_obj_mutex = gsc_handle->obj_mutex[i]; flag_find_new_gsc = true; @@ -729,6 +734,7 @@ void *exynos_gsc_create( gsc_handle->obj_mutex[i] = NULL; gsc_handle->cur_obj_mutex = NULL; + gsc_handle->destroy_cur_obj_mutex = false; gsc_handle->flag_local_path = false; gsc_handle->flag_exclusive_open = false; @@ -813,6 +819,7 @@ void *exynos_gsc_reserve(int dev_num) gsc_handle->gsc_fd = -1; gsc_handle->op_mutex = NULL; gsc_handle->cur_obj_mutex = NULL; + gsc_handle->destroy_cur_obj_mutex = true; sprintf(mutex_name, "%sObject%d", LOG_TAG, dev_num); gsc_handle->cur_obj_mutex = exynos_mutex_create(EXYNOS_MUTEX_TYPE_SHARED, mutex_name); @@ -908,6 +915,7 @@ void *exynos_gsc_create_exclusive( gsc_handle->obj_mutex[i] = NULL; gsc_handle->cur_obj_mutex = NULL; + gsc_handle->destroy_cur_obj_mutex = false; gsc_handle->flag_local_path = false; gsc_handle->flag_exclusive_open = true; @@ -928,6 +936,7 @@ void *exynos_gsc_create_exclusive( ALOGE("%s::exynos_mutex_create(%s) fail", __func__, mutex_name); goto err; } + gsc_handle->destroy_cur_obj_mutex = true; do { if (exynos_mutex_trylock(gsc_handle->cur_obj_mutex) == true) { @@ -965,8 +974,11 @@ err: if (gsc_handle) { m_exynos_gsc_destroy(gsc_handle); - if (gsc_handle->cur_obj_mutex) + if (gsc_handle->cur_obj_mutex) { exynos_mutex_unlock(gsc_handle->cur_obj_mutex); + if (gsc_handle->destroy_cur_obj_mutex) + exynos_mutex_destroy(gsc_handle->cur_obj_mutex); + } for (i = 0; i < NUM_OF_GSC_HW; i++) { if ((gsc_handle->obj_mutex[i] != NULL) && @@ -1023,6 +1035,9 @@ void exynos_gsc_destroy( } } + if (gsc_handle->destroy_cur_obj_mutex) + exynos_mutex_destroy(gsc_handle->cur_obj_mutex); + exynos_mutex_unlock(gsc_handle->op_mutex); if (exynos_mutex_destroy(gsc_handle->op_mutex) == false) -- 2.20.1