tbm_bo: free hal_tbm_bo when it is allocated by tbm_bo_alloc
[platform/core/uifw/libtbm.git] / src / tbm_bo.c
index 044b5ec..0f2b138 100644 (file)
@@ -384,6 +384,7 @@ tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags)
                }
                /* LCOV_EXCL_STOP */
                bo->bo_data = bo_data;
+               bo->allocated_hal_tbm_bo = 1;
        } else if (bufmgr->backend_module_data) {
                bo_data = bufmgr->bufmgr_func->bufmgr_alloc_bo(bufmgr->bufmgr_data, (unsigned int)size, flags, &error);
                if (!bo_data) {
@@ -1625,8 +1626,12 @@ _tbm_bo_free(tbm_bo bo)
 
        /* call the bo_free */
        if (bo->bufmgr->use_hal_tbm) {
-               hal_tbm_bo_free(bo->bo_data);
-               bo->bo_data = NULL;
+               // call hal_tbm_bo_free when bo is created by tbm_bo_alloc api.
+               if (bo->allocated_hal_tbm_bo) {
+                       hal_tbm_bo_free(bo->bo_data);
+                       bo->bo_data = NULL;
+                       bo->allocated_hal_tbm_bo = 0;
+               }
        } else if (bo->bufmgr->backend_module_data) {
                bo->bufmgr->bo_func->bo_free(bo->bo_data);
                bo->bo_data = NULL;