-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NetBSD: Process.connections() leaks memory or segfaults #930
Comments
Hi @ryoon / @ryoqun. Long time no see. Sorry to bother you, but I remember you wrote this code, and I don't know how to fix it (test has been failing for years literally). We have a memory leak that is easily reproducible on NetBSD with:
If you run psutil/psutil/arch/netbsd/socks.c Lines 321 to 322 in 69bca49
Memory is being allocated at: psutil/psutil/arch/netbsd/socks.c Lines 148 to 149 in 69bca49
...and it's supposed to be freed in: psutil/psutil/arch/netbsd/socks.c Lines 79 to 87 in 69bca49
...but it doesn't. Do you think you have some time to take a look at this? The code is too arcane to me. Thank you. CC @0-wiz-0 |
Hi @giampaolo
(completely untested) |
Thank you @0-wiz-0 , that worked as intended, meaning that some memory gets freed. I committed a change here: I can solve the memory leak completely if I decomment these 2
|
Ok... looking closer I see that pointers into these two blocks of memory are kept active psutil/psutil/arch/netbsd/socks.c Line 127 in f3d401d
and psutil/psutil/arch/netbsd/socks.c Line 139 in f3d401d
So I think one solution would be to replace the pointer: psutil/psutil/arch/netbsd/socks.c Line 143 in f3d401d
with a copy. I.e. malloc another struct kinfo_file ki , copy the contents of &ki[j] into it and use it for kif->kif , and free it in the loops you just modified (and similar for struct kinfo_pcb kp in the pcb loop).
Then you can uncomment the |
I'm glad you could fix this - thank you! |
I am sorry. I am too late. Thank you very much for your fix. |
UPDATE
Actually it also segfaults:
The text was updated successfully, but these errors were encountered: