Skip to content

fix: Ensure pthread_mutexattr_t is properly cleaned up with pthread_mutexattr_destroy in Lock#3480

Merged
Lukasa merged 2 commits intoapple:mainfrom
PassiveLogic:fix/lockMemoryLeak
Jan 19, 2026
Merged

fix: Ensure pthread_mutexattr_t is properly cleaned up with pthread_mutexattr_destroy in Lock#3480
Lukasa merged 2 commits intoapple:mainfrom
PassiveLogic:fix/lockMemoryLeak

Conversation

@scottmarchant
Copy link
Copy Markdown
Contributor

Motivation:

In reviewing a copy of this file in swift-log, @czechboy0 noticed that the call to pthread_mutexattr_destroy is missing. Since pthread_mutexattr_t is like allocated on the stack rather than heap on most platforms, this is likely not a memory leak. But for correctness the missing destroy call should be added.

This change is the start of a resolution requested in a corresponding Lock rollout in swift-log

Modifications:

  • Added missing call to pthread_mutexattr_destroy
  • Duplicated test for NIOLock to also test Lock, as a sanity test.

Result:

The new sanity test passes. If there are other ways this change can be realistically verified as safe and proper, please feel free to provide feedback in the PR.

Copy link
Copy Markdown
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@Lukasa
Copy link
Copy Markdown
Contributor

Lukasa commented Jan 16, 2026

Mind cleaning up the soundness script report?

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Jan 16, 2026
@scottmarchant
Copy link
Copy Markdown
Contributor Author

Mind cleaning up the soundness script report?

@Lukasa I believe the soundness action passes now. Apologies for missing that the first go around. Verified the check independently in a fork.

@Lukasa Lukasa merged commit 6ce9173 into apple:main Jan 19, 2026
53 of 54 checks passed
kukushechkin pushed a commit to apple/swift-log that referenced this pull request Feb 12, 2026
…408)

Ports changes to `Lock` from swift-nio to swift-log.

### Motivation:

The copy-paste of `Lock` in swift-log should be updated with changes
from swift-nio.

### Modifications:

- Rolls back changed [made previously for
FreeBSD](https://github.com/apple/swift-log/pull/387/changes#diff-7b1bd45403dd1a7418287bd60682bf05ba2e4bf75dca1c0ca55a86d0477c9af5L73)
in favor of a consolidated implementation in swift-nio that will be in
place once apple/swift-nio#3494 merges. @kkebo
Please confirm this works. After both of our PR's merge, swift-log and
swift-nio will have the same implementation as far as FreeBSD is
concerned.
- Brought the following recent changes from swift-nio over to swift-log:

  - apple/swift-nio#3482
  - apple/swift-nio#3480
  - apple/swift-nio#3483

- Removed stale `// SRWLOCK does not need to be free'd` comment.

### Result:

`Lock` implementation will have the same implementation as swift-nio
(assuming apple/swift-nio#3494 merges).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants