Skip to content

An improper locking due to the unreleased lock before program exit #322

@ryancaicse

Description

@ryancaicse

Hi developers, in the below codes, the lock &T->mtx could be not released before program's exit exit(1); when noeintr_write(T->wakeupsock[0], &zero, 1) != 1 . I think there is no harm to write pthread_mutex_unlock(&T->mtx) before the exit(1); for better resource management and code symmetry. Thanks!

if ((rc = pthread_mutex_lock(&T->mtx)) != 0) {
warn0("pthread_mutex_lock: %s", strerror(rc));
exit(1);
}
/* Write the answer back. */
T->sas = sas;
T->res_errno = res_errno;
/* Send a completion message. */
if (noeintr_write(T->wakeupsock[0], &zero, 1) != 1) {
warnp("Error writing to wakeup socket");
exit(1);
}

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