jaraco / keyring

MIT License
1.24k stars 152 forks source link

Memory Leak on MacOS #670

Open peterallenwebb opened 5 months ago

peterallenwebb commented 5 months ago

Calling the keyring.get_password() function repeatedly on MacOS results in leaked memory. The problem appears to be in find_generic_password(), 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.

jaraco commented 5 months ago

Thanks for reporting. Sounds like a bug to me. I'm also not exactly familiar with the object lifecycle management in CoreFoundation, so I welcome your contrib (or someone else). If someone starts on it, let me know so I can assign the issue to you and avoid duplication of work.