From 665206000b8307cab5ac51203d29b0f232d7e31b Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Wed, 2 Oct 2024 14:21:48 +0100 Subject: [PATCH] ConditionLock deallocs its pthread_cond_t in more cases (#2901) ### 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. --- Sources/NIOConcurrencyHelpers/lock.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/NIOConcurrencyHelpers/lock.swift b/Sources/NIOConcurrencyHelpers/lock.swift index 44845e8282..42e2a3533c 100644 --- a/Sources/NIOConcurrencyHelpers/lock.swift +++ b/Sources/NIOConcurrencyHelpers/lock.swift @@ -159,8 +159,6 @@ public final class ConditionLock { #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 }