mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-12-24 11:50:58 +08:00
[mpp_mem_pool]: Add finalized check
Add finalized flag to avoid double free error which happened on C++ static destruction function order error. If ~MppMemPoolService is called first in __cxa_finalize then another C++ static destruction function call mpp_mem_pool function later it will cause double free crash. Signed-off-by: Herman Chen <herman.chen@rock-chips.com> Change-Id: I14862e74d7987e30cccbcbaaee21170d92aa62d9
This commit is contained in:
@@ -52,6 +52,9 @@ typedef struct MppMemPoolImpl_t {
|
||||
struct list_head unused;
|
||||
RK_S32 used_count;
|
||||
RK_S32 unused_count;
|
||||
|
||||
/* extra flag for C++ static destruction order error */
|
||||
RK_S32 finalized;
|
||||
} MppMemPoolImpl;
|
||||
|
||||
class MppMemPoolService
|
||||
@@ -110,6 +113,7 @@ MppMemPoolImpl *MppMemPoolService::get_pool(size_t size)
|
||||
pool->size = size;
|
||||
pool->used_count = 0;
|
||||
pool->unused_count = 0;
|
||||
pool->finalized = 0;
|
||||
|
||||
INIT_LIST_HEAD(&pool->used);
|
||||
INIT_LIST_HEAD(&pool->unused);
|
||||
@@ -126,9 +130,12 @@ void MppMemPoolService::put_pool(MppMemPoolImpl *impl)
|
||||
|
||||
if (impl != impl->check) {
|
||||
mpp_err_f("invalid mem impl %p check %p\n", impl, impl->check);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
if (impl->finalized)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&impl->lock);
|
||||
|
||||
if (!list_empty(&impl->unused)) {
|
||||
@@ -158,6 +165,7 @@ void MppMemPoolService::put_pool(MppMemPoolImpl *impl)
|
||||
list_del_init(&impl->service_link);
|
||||
}
|
||||
|
||||
impl->finalized = 1;
|
||||
mpp_free(impl);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user