jaraco / jaraco/keyring

Memory Leak on MacOS

Open
#670 2 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Python
Stars
1.5k
Forks
196
PR merge metrics
No merged PRs in 30d

Description

Calling the `keyring.get_password()` function repeatedly on MacOS results in leaked memory. The problem appears to be in [find_generic_password()](https://github.com/jaraco/keyring/blob/f3e711d237ad94314dd5738667ee5ed6bc2f33e6/keyring/backends/macOS/api.py#L142C1-L159C30), where the memory allocated by `SecItemCopyMatching()` is never released. I spent some time trying to fix the issue, but it was dragging me further into the world of CoreFoundation internals than I had time to go.

I don't know how serious the problem is in practice, but using memray I was seeing a non-negligible memory allocation (~30MB) hanging around in my application, attributable to this function.

Thank you so much for your work maintaining this library! If I have more time soon I might return to the issue and attempt a fix.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in keyring/backends/macOS/api.py at find_generic_password(), especially the SecItemCopyMatching() call and the surrounding CoreFoundation handling. Use the reported repeated keyring.get_password() scenario and memray to investigate; done means the allocation no longer accumulates while the lookup continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, python
Domain
desktop, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.