Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
| test.cpp:303:11:303:18 | call to try_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
| test.cpp:313:11:313:18 | call to try_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
| test.cpp:442:8:442:17 | call to mutex_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
| test.cpp:482:2:482:19 | call to pthread_mutex_lock | This lock might not be unlocked or might be locked more times than it is unlocked. |
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,46 @@ bool test_mutex(data_t *data)

return true;
}

// ---

struct pthread_mutex
{
// ...
};

void pthread_mutex_lock(pthread_mutex *m);
void pthread_mutex_unlock(pthread_mutex *m);

class MyClass
{
public:
pthread_mutex lock;
};

bool maybe();

int test_MyClass_good(MyClass *obj)
{
pthread_mutex_lock(&obj->lock);

if (maybe()) {
pthread_mutex_unlock(&obj->lock);
return -1; // GOOD
}

pthread_mutex_unlock(&obj->lock); // GOOD
return 0;
}

int test_MyClass_bad(MyClass *obj)
{
pthread_mutex_lock(&obj->lock);

if (maybe()) {
return -1; // BAD
}

pthread_mutex_unlock(&obj->lock); // GOOD
return 0;
}