Skip to content

Potential error(e.g., deadlock, ill peformance) due to the &stats.lock #964

@jenny-cheung

Description

@jenny-cheung

Hi, developers, thank you for your checking. The lock &stats.lock may not be correctly released if the realloc fails. Finally, the method returns with the unreleased lock. The fix is to insert pthread_mutex_unlock(&stats.lock); before returning.

ncm_session_add(struct nc_session *session)

pthread_mutex_lock(&stats.lock);

void
ncm_session_add(struct nc_session *session)
{
    ...;
    pthread_mutex_lock(&stats.lock);

    ++stats.in_sessions;

    ++stats.session_count;
    new = realloc(stats.sessions, stats.session_count * sizeof *stats.sessions);
    if (!new) {
        EMEM;
        return; //return without releasing the lock
    }
    stats.sessions = new;
    new = realloc(stats.session_stats, stats.session_count * sizeof *stats.session_stats);
    if (!new) {
        EMEM;
        return; //return without releasing the lock
    }
    ...;

    pthread_mutex_unlock(&stats.lock);
}

Best,

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:bugBug description.status:completedFrom the developer perspective, the issue was solved (bug fixed, question answered,...)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions