cherokee / webserver

Cherokee Web Server
GNU General Public License v2.0
568 stars 104 forks source link

A potential error due to the unreleased lock #1267

Open ycaibb opened 3 years ago

ycaibb commented 3 years ago

Dear developers: thank you for your checking. It seems the lock srv->main_thread->ownership is also not released if the ret==ret_ok .

ret_t
cherokee_server_close_connection (cherokee_server_t *srv, cherokee_thread_t *mythread, char *id_str)
{
    ...;
    if (srv->main_thread != mythread) CHEROKEE_MUTEX_LOCK (&srv->main_thread->ownership);

    ret = thread_find_connection (srv->main_thread, id);
    if (ret == ret_ok) return ret; // the lock srv->main_thread->ownership is not released.

    if (srv->main_thread != mythread) CHEROKEE_MUTEX_UNLOCK (&srv->main_thread->ownership);

    list_for_each (t, &srv->thread_list) {
        cherokee_thread_t *thread = THREAD(t);

        if (thread != mythread) CHEROKEE_MUTEX_LOCK (&thread->ownership);

        ret = thread_find_connection (thread, id);

        if (thread != mythread) CHEROKEE_MUTEX_UNLOCK (&thread->ownership);

        if (ret == ret_ok) return ret;
    }

    return ret_not_found;
}

Best,