[meta/buffer]: Fix usage after service is destoyed

When C++ global destructor is called MppBufferService and MppMetaService
maybe be called before other destructors which may call mpp_buffer_put
and mpp_meta_put. So we mark finished flag after ~MppBufferService and
~MppMetaService is call and so not free corresponding data again.

This case usually happens when user call exit() directly.

Change-Id: I997c49b095e443b061fca230587b6216f710d31c
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2020-10-19 17:38:24 +08:00
parent fa3478c309
commit 0520b7d35d
2 changed files with 13 additions and 1 deletions

View File

@@ -75,6 +75,7 @@ private:
RK_U32 group_id; RK_U32 group_id;
RK_U32 group_count; RK_U32 group_count;
RK_U32 finalizing; RK_U32 finalizing;
RK_U32 finished;
// misc group for internal / externl buffer with different type // misc group for internal / externl buffer with different type
MppBufferGroupImpl *misc[MPP_BUFFER_MODE_BUTT][MPP_BUFFER_TYPE_BUTT]; MppBufferGroupImpl *misc[MPP_BUFFER_MODE_BUTT][MPP_BUFFER_TYPE_BUTT];
@@ -604,6 +605,7 @@ MppBufferService::MppBufferService()
: group_id(0), : group_id(0),
group_count(0), group_count(0),
finalizing(0), finalizing(0),
finished(0),
misc_count(0) misc_count(0)
{ {
RK_S32 i, j; RK_S32 i, j;
@@ -655,6 +657,7 @@ MppBufferService::~MppBufferService()
deinit_buffer_no_lock(pos, __FUNCTION__); deinit_buffer_no_lock(pos, __FUNCTION__);
} }
} }
finished = 1;
} }
RK_U32 MppBufferService::get_group_id() RK_U32 MppBufferService::get_group_id()
@@ -745,6 +748,9 @@ void MppBufferService::set_misc(MppBufferMode mode, MppBufferType type, MppBuffe
void MppBufferService::put_group(MppBufferGroupImpl *p) void MppBufferService::put_group(MppBufferGroupImpl *p)
{ {
if (finished)
return ;
buffer_group_add_log(p, NULL, GRP_RELEASE, __FUNCTION__); buffer_group_add_log(p, NULL, GRP_RELEASE, __FUNCTION__);
// remove unused list // remove unused list

View File

@@ -69,6 +69,7 @@ private:
RK_U32 meta_id; RK_U32 meta_id;
RK_U32 meta_count; RK_U32 meta_count;
RK_U32 node_count; RK_U32 node_count;
RK_U32 finished;
public: public:
static MppMetaService *get_instance() { static MppMetaService *get_instance() {
@@ -101,7 +102,8 @@ public:
MppMetaService::MppMetaService() MppMetaService::MppMetaService()
: meta_id(0), : meta_id(0),
meta_count(0), meta_count(0),
node_count(0) node_count(0),
finished(0)
{ {
INIT_LIST_HEAD(&mlist_meta); INIT_LIST_HEAD(&mlist_meta);
INIT_LIST_HEAD(&mlist_node); INIT_LIST_HEAD(&mlist_node);
@@ -128,6 +130,7 @@ MppMetaService::~MppMetaService()
put_node(pos); put_node(pos);
} }
} }
finished = 1;
} }
RK_S32 MppMetaService::get_index_of_key(MppMetaKey key, MppMetaType type) RK_S32 MppMetaService::get_index_of_key(MppMetaKey key, MppMetaType type)
@@ -166,6 +169,9 @@ MppMetaImpl *MppMetaService::get_meta(const char *tag, const char *caller)
void MppMetaService::put_meta(MppMetaImpl *meta) void MppMetaService::put_meta(MppMetaImpl *meta)
{ {
if (finished)
return ;
mpp_assert(meta->ref_count); mpp_assert(meta->ref_count);
if (meta->ref_count) if (meta->ref_count)
meta->ref_count--; meta->ref_count--;