Skip to content

check / wait condition issue in test/main.c #141

@nefigtut

Description

@nefigtut

Hello,
I'm not sure if code in test/ directory is important enough, still let me report an issue found by Openscanhub code security scanner:

1. Defect type: BAD_CHECK_OF_WAIT_COND
QATzip-1.3.1/test/main.c:6225:54: dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock "mutex". This can cause a deadlock if the notification happens before the lock is acquired.
 
2. Defect type: BAD_CHECK_OF_WAIT_COND
QATzip-1.3.1/test/main.c:6151:54: dead_wait: A wait is performed without ensuring that the condition is not already satisfied while holding lock "mutex". This can cause a deadlock if the notification happens before the lock is acquired.

The code there (1) and (2) shows just a single pthread_cond_wait(). The man page suggests, the recommended approarch is to nest it inside while(cond). Please, see Block on a Condition Variable at text "Because the condition can change before an awakened thread returns from pthread_cond_wait()...".

I'm not sure if this is not a false positive, as the code seemingly does not have "a condition expression which is evaluated under the protection of a mutex lock". Could you please have a look?

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