maxgoedjen / secretive

Store SSH keys in the Secure Enclave
MIT License
7.24k stars 159 forks source link

SecretAgent leaks 35 MB of memory per request #246

Closed mologie closed 2 years ago

mologie commented 3 years ago

Hi,

I was surprised to find SecretAgent using as much memory as Firefox and started to investigate. Attached is a video reproducing a memory leak, where simply opening and closing an SSH session increases SecretAgent's memory usage by 30-40MB each.

Sometimes memory usage drops back to ~7MB once I click "Deny" in a confirmation/fingerprint prompt, but this does not happen reliably and SecretAgent mostly keeps a ridiculous amount of memory until killed via Activity Monitor.

Version: 2.1.1 (1.1111024541) macOS: 11.6 (20G165) MacBook Air, M1 2020

https://user-images.githubusercontent.com/597682/136625128-af6ba56b-8a96-42a6-a6c1-68b5ab5af22f.mov

maxgoedjen commented 3 years ago

https://user-images.githubusercontent.com/342665/136682469-c3575c23-033b-4765-94a8-145a4887f461.mov

Are you seeing this in normal usage? Testing here (video above) shows that it might take a moment or two to be reclaimed, but doesn't appear to leak. I'm wondering if this is just really visible due to the tight loop in your demo video.

mologie commented 3 years ago

Yes I do see that during normal usage. When I made the report I actually wanted to look at memory/CPU usage of the Apple Silicon mpv build of mine. I had not used SSH for hours.

Just now I had a look at the memory usage of SecretAgent on the same machine: It's been in my bag for ~2h and was active in the morning for ~4h, and SecretAgent is at 120MiB. To confirm, I have opened another SSH session, closed it, and waited a minute -- memory usage increased to 150MiB and did not go back down.