Skip to content

Potential error(e.g., deadlock) due to the unreleased lock&bktr_mutex #1364

@jenny-cheung

Description

@jenny-cheung

Dear developers:
First, thank you for your checking. In the method, bktr_start(struct context *cnt), the lock &bktr_mutex may not be released correctly if the branch conditionioctl(dev->fd_device, METEORCAPTUR, &dummy) < 0satisfies. Specifically, the lock is always released in the other place where the method returns except this.

The fix is to insert the pthread_mutex_unlock(&bktr_mutex); before returning.

pthread_mutex_lock(&bktr_mutex);

if (ioctl(dev->fd_device, METEORCAPTUR, &dummy) < 0) {

int bktr_start(struct context *cnt)
{
         ...;

        pthread_mutex_lock(&bktr_mutex); // the lock

      ...;
        while (dev) {
            if (mystreq(conf->video_device, dev->video_device)) {
                int dummy = METEOR_CAP_STOP_CONT;
                dev->usage_count++;

                if (ioctl(dev->fd_device, METEORCAPTUR, &dummy) < 0) {
                    MOTION_LOG(CRT, TYPE_VIDEO, SHOW_ERRNO,_("Stopping capture"));
                    return -1; //return without releasing the lock
                }

                MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
                    ,_("Reusing [%s] inputs [%d,%d] Change capture"
                    " method METEOR_CAP_SINGLE")
                    , dev->video_device, dev->input, cnt->param_input);

                dev->bktr_method = METEOR_CAP_SINGLE;


                MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
                    ,_("VIDEO_PALETTE_YUV420P setting"
                    " imgs.size_norm and imgs.motionsize"));
                cnt->imgs.motionsize = width * height;
                cnt->imgs.size_norm = (width * height * 3) / 2;

                pthread_mutex_unlock(&bktr_mutex);
                return dev->fd_device; // FIXME return bktr_fdtuner ?!
            }
            dev = dev->next;
        }


      ...;
}

Best,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions