threadWaitQuit returns with the mutex locked, then threadFree destroys it
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 78/100
Research direction
The bug is in threadWaitQuit in lib/SRC/ARUtil/thread_sub.c (lines 246-255), which returns while still holding flag->mut; the destroy call is in threadFree at line 198. Read both functions to confirm the lock is never released on the return path, then add pthread_mutex_unlock before return 0. Done when the function unlocks before returning and the ThreadSanitizer run no longer reports destroy of a locked mutex at thread_sub.c:198.
Written by the indexing model from the issue text.
Description
Description
threadWaitQuit() in lib/SRC/ARUtil/thread_sub.c (lines 246-255) locks flag->mut, waits on cond2 until endF == 2, and returns without unlocking. Callers then call threadFree() (line 196+), whose first step is pthread_mutex_destroy(&(*flag)->mut) (line 198): destroying a locked mutex is undefined behaviour in POSIX.
int threadWaitQuit( THREAD_HANDLE_T *flag )
{
pthread_mutex_lock(&(flag->mut));
flag->startF = 2;
pthread_cond_signal(&(flag->cond1));
while (flag->endF != 2) {
pthread_cond_wait(&(flag->cond2), &(flag->mut));
}
return 0; // mut is still locked here
}
Evidence
A ThreadSanitizer run of the NFT core tests (webarkit/jsartoolkitNFT#683, webarkit_nft_core_test, filters ThreadedKpmDetectorTest.*:CoreLifecycleTest.*:CoreTrackingTest.Threaded*) passed 16/16 but reported 61 destroy of a locked mutex warnings, all at threadFree (thread_sub.c:198), reached through trackingInitQuit (KPM worker shutdown) and ar2DeleteHandle (threaded AR2 workers).
Pre-existing: every ARToolKit5 consumer of threadWaitQuit + threadFree has it; glibc tolerates it in practice, which is why it never showed up.
Fix
Add pthread_mutex_unlock(&(flag->mut)); before return 0; in threadWaitQuit. Then a sanitizer CI job could run without suppressions for this file.
- Dominant language
- C++
- Stars
- 21
- Forks
- 8
- Avg merge
- 6h 43m
- Merged PRs (30d)
- 18
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from webarkit/WebARKitLib
-
bug C/C++ code
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
webarkit/WebARKitLib#84 ·
Maintainers usually reply within 1 day
-
Sync workflow: handle a conflicting sync branch with no open PR, and PRs the workflow did not openOpenCI enhancement
Difficulty 3/5 Half a day Newbie friendliness 45/100
webarkit/WebARKitLib#92 ·
Maintainers usually reply within 1 day
-
Optical tracker: frames without a marker run detection twice since the #53 full-resolution retryOpenC/C++ code enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
webarkit/WebARKitLib#91 ·
Maintainers usually reply within 1 day
-
C/C++ code enhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
webarkit/WebARKitLib#87 ·
Maintainers usually reply within 1 day
-
bug C/C++ code
Difficulty 3/5 Half a day Newbie friendliness 66/100
webarkit/WebARKitLib#86 ·
Maintainers usually reply within 1 day
All issues in webarkit/WebARKitLib
Similar issues
-
ai_p2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ClickHouse/ClickHouse#125522 ·
Maintainers usually reply within 1 day
-
[BUG] The priority slider's keyboard-hints tooltip shows on the 'Default' label, not the sliderOpenagent:WSL bug linux LOW ui
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Branch-3.3.5a
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
TrinityCore/TrinityCore#32060 ·
Maintainers usually reply within 3 days
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
open-telemetry/opentelemetry-cpp#4697 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
secondlife/viewer#6432 · 1 comment ·
Maintainers usually reply within 1 day