13 Star 22 Fork 8

OpenHarmony / multimedia_frameworks_recorder_lite

【讨论】recorder_impl.cpp中Release->Stop调用流程,涉及到对同一个mutex,进行加锁两次

Task
Backlog
Gymee  Opened this issue

该问题是怎么引起的?

函数调用过程存在对同一个mutex进行加锁两次,会导致程序崩溃或未定义行为

重现步骤

报错信息

代码地址

int32_t Recorder::RecorderImpl::Stop(bool block)
{
    std::lock_guard<std::mutex> lock(mutex_); // 问题代码(对mutex_再次已经加锁)
    if (status_ != RECORDING &&
        status_ != PAUSED) {
        MEDIA_ERR_LOG(" Stop ILLEGAL_STATE  status:%u", status_);
        return ERR_ILLEGAL_STATE;
    }

int32_t Recorder::RecorderImpl::Release()
{
    std::lock_guard<std::mutex> lock(mutex_); // 对mutex_已经加锁
    int32_t ret;
    if ((ret = InitCheck()) != SUCCESS) {
        MEDIA_ERR_LOG("Release InitCheck err");
        return ret;
    }
    if (status_ == RECORDING ||
        status_ == PAUSED) {
        if ((ret = Stop(false)) != SUCCESS) {  // 问题代码
            MEDIA_ERR_LOG("Release Stop err");
            return ret;
        }
    }

问题原始发现人@jiangyubo_zju

Attachments
total 1 participants

Comments (1)

Gymee 2020-09-14 12:00

建议:

  1. Stop内去掉加锁动作,在命名上要突出调用者已经加锁了,例如可以改成StopLocked等
  2. 使用recursive_mutex

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority
1
https://git.oschina.net/openharmony/multimedia_frameworks_recorder_lite.git
git@git.oschina.net:openharmony/multimedia_frameworks_recorder_lite.git
openharmony
multimedia_frameworks_recorder_lite
multimedia_frameworks_recorder_lite

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542