Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ConditionLock deallocs its pthread_cond_t in more cases #2901

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

rnro
Copy link
Contributor

@rnro rnro commented Oct 2, 2024

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 waiting 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.

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.
@rnro rnro force-pushed the ConditionLock_leak branch from 4d94a44 to 3f65c08 Compare October 2, 2024 12:32
@rnro rnro added 🆕 semver/minor Adds new public API. 🔨 semver/patch No public API change. and removed 🆕 semver/minor Adds new public API. labels Oct 2, 2024
@Lukasa
Copy link
Contributor

Lukasa commented Oct 2, 2024

Worth considering whether we should add a regression benchmark test for this.

@rnro rnro merged commit 6652060 into apple:main Oct 2, 2024
30 of 32 checks passed
@rnro rnro deleted the ConditionLock_leak branch October 2, 2024 13:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants