Skip to content

Commit 233f61b

Browse files
authored
Initialize the mutexattr before use. (#3482)
As observed by @kkebo, this was missing from the implementation. ### Motivation: Correct pthread API usage. ### Modifications: Initialize the pthread_mutexattr_t with pthread_mutexattr_init before passed to pthread_mutex_init. ### Result: Even though this lock API appears to be deprecated, we'll correct the usage anyway. The non-deprecated NIOLock class doesn't have this problem.
1 parent 6ce9173 commit 233f61b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Sources/NIOConcurrencyHelpers/lock.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public final class Lock {
5757
InitializeSRWLock(self.mutex)
5858
#elseif os(OpenBSD)
5959
var attr = pthread_mutexattr_t(bitPattern: 0)
60-
let err = pthread_mutex_init(self.mutex, &attr)
60+
var err = pthread_mutexattr_init(&attr)
61+
precondition(err == 0, "\(#function) failed in pthread_mutexattr_init with error \(err)")
62+
err = pthread_mutex_init(self.mutex, &attr)
6163
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
6264
#elseif (compiler(<6.1) && !os(WASI)) || (compiler(>=6.1) && _runtime(_multithreaded))
6365
var attr = pthread_mutexattr_t()

0 commit comments

Comments
 (0)