exynos5: omx: osal: only free sharedmem buffers we allocated
authorDima Zavin <dima@android.com>
Tue, 4 Sep 2012 22:03:42 +0000 (15:03 -0700)
committerDima Zavin <dima@android.com>
Tue, 4 Sep 2012 22:03:45 +0000 (15:03 -0700)
Buffers that get imported should not be freed as omx doesn't
own them.

Change-Id: I1667879937a2e855bbccc7276fa15eb333401dc9
Signed-off-by: Dima Zavin <dima@android.com>
exynos_omx/openmax/exynos_omx/osal/Exynos_OSAL_SharedMemory.c

index d9aaee13e76febea022d5f8e88a14b8a2a62227c..9d2dea3ae05d56721d1183a4fd2404102df50de5 100644 (file)
@@ -25,6 +25,7 @@
  *   2012.02.20 : Create
  */
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -49,6 +50,7 @@ typedef struct _EXYNOS_SHAREDMEM_LIST
     OMX_U32                        IONBuffer;
     OMX_PTR                        mapAddr;
     OMX_U32                        allocSize;
+    bool                           owner;
     struct _EXYNOS_SHAREDMEM_LIST *pNextMemory;
 } EXYNOS_SHAREDMEM_LIST;
 
@@ -109,7 +111,8 @@ void Exynos_OSAL_SharedMemory_Close(OMX_HANDLETYPE handle)
         pDeleteElement->mapAddr = NULL;
         pDeleteElement->allocSize = 0;
 
-        ion_free(pDeleteElement->IONBuffer);
+        if (pDeleteElement->owner)
+            ion_free(pDeleteElement->IONBuffer);
         pDeleteElement->IONBuffer = 0;
 
         Exynos_OSAL_Free(pDeleteElement);
@@ -149,6 +152,7 @@ OMX_PTR Exynos_OSAL_SharedMemory_Alloc(OMX_HANDLETYPE handle, OMX_U32 size, MEMO
 
     pElement = (EXYNOS_SHAREDMEM_LIST *)Exynos_OSAL_Malloc(sizeof(EXYNOS_SHAREDMEM_LIST));
     Exynos_OSAL_Memset(pElement, 0, sizeof(EXYNOS_SHAREDMEM_LIST));
+    pElement->owner = true;
 
     switch (memoryType) {
     case SECURE_MEMORY:
@@ -256,7 +260,8 @@ void Exynos_OSAL_SharedMemory_Free(OMX_HANDLETYPE handle, OMX_PTR pBuffer)
     pDeleteElement->mapAddr = NULL;
     pDeleteElement->allocSize = 0;
 
-    ion_free(pDeleteElement->IONBuffer);
+    if (pDeleteElement->owner)
+        ion_free(pDeleteElement->IONBuffer);
     pDeleteElement->IONBuffer = 0;
 
     Exynos_OSAL_Free(pDeleteElement);