libgscaler: fix a mutex leak
authorChien-Yu Chen <cychen@google.com>
Tue, 11 Nov 2014 19:46:54 +0000 (11:46 -0800)
committerChien-Yu Chen <cychen@google.com>
Tue, 11 Nov 2014 21:51:03 +0000 (13:51 -0800)
Bug: 11132653
Change-Id: I23ab470682d3483a7c2e5666c91db232e6c57a27

libgscaler/exynos_gsc_utils.h
libgscaler/exynos_gscaler.c

index 8c0217f1718df98ceb18b6e93560df3337f47fd4..8e5c49dbc2a6cbcec6791bf9b69e55ae065dceac 100644 (file)
@@ -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;
index 360812b89629ed95fbd6d8048dbb4fb3e77cdbea..0e7bb77c53fa88a88e93369e8da65c24efd39823 100644 (file)
@@ -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)