Skip to content

Commit

Permalink
ConditionLock deallocs its pthread_cond_t in more cases (#2901)
Browse files Browse the repository at this point in the history
### Motivation:

Recently we changed the init and deinit behavior of `ConditionLock`, at
that time the `UnsafeMutablePointer` allocation of the held
`pthread_cond_t` was put behind a conditional compiler and runtime
check. The deallocation of the same object was also put behind a
conditional, however the conditions were mismatched leading to a leak on
some platforms. Notably this surfaced when `wait`ing on an event loop
future.

### Modifications:

`ConditionLock.deinit` now deallocs the held `pthread_cond_t` under the
same conditions in which it allocs it.

### Result:

Creating a `ConditionLock` no longer leaks memory.
  • Loading branch information
rnro authored Oct 2, 2024
1 parent fb87d5e commit 6652060
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Sources/NIOConcurrencyHelpers/lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ public final class ConditionLock<T: Equatable> {
#elseif (compiler(<6.1) && !os(WASI)) || (compiler(>=6.1) && _runtime(_multithreaded))
let err = pthread_cond_destroy(self.cond)
precondition(err == 0, "\(#function) failed in pthread_cond with error \(err)")
#endif
#if compiler(>=6.1) && _runtime(_multithreaded)
self.cond.deallocate()
#endif
}
Expand Down

0 comments on commit 6652060

Please sign in to comment.