Skip to content
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

Possible memory leak #25

Open
robol opened this issue Sep 8, 2020 · 4 comments
Open

Possible memory leak #25

robol opened this issue Sep 8, 2020 · 4 comments

Comments

@robol
Copy link
Owner

robol commented Sep 8, 2020

A memory leak has been reported at the end of the discussion in Issue #23. It seems less severe than the first one reported in that issues (which has been solved).

@rusins
Copy link

rusins commented Feb 24, 2021

I believe I've found the leak (or maybe another).

In src/libmps/floating-point/mpc.c

function void mpc_mul has the line

s1 = init (mpf_get_prec (mpc_Re (rc)));

and the init function has the line

ptr = create_new_mps_tls (precision_needed);

and then the create_new_mps_tls function of course does

ptr = mps_new (mps_tls);

which is a call to mps_malloc that never gets freed.

At least that's what I gathered from Valgrind

==618677== 32 bytes in 1 blocks are still reachable in loss record 1 of 3
==618677==    at 0x483E77F: malloc (vg_replace_malloc.c:307)
==618677==    by 0x4C21179: mps_malloc (in /usr/lib/libmps.so.3.0.1)
==618677==    by 0x4C2E2FC: ??? (in /usr/lib/libmps.so.3.0.1)
==618677==    by 0x4C2EC44: mpc_mul (in /usr/lib/libmps.so.3.0.1)
==618677==    by 0x4C4CC1E: ??? (in /usr/lib/libmps.so.3.0.1)
==618677==    by 0x4C4CE6E: ??? (in /usr/lib/libmps.so.3.0.1)

@advanpix
Copy link

advanpix commented Apr 13, 2021

@rusin Looks like these allocations are properly freed in mps_mpc_cache_cleanup.
Code is just a bit convoluted, init allocates in thread TLS memory. All per-thread allocations then freed with mps_mpc_cache_cleanup on thread exit.

@rusins
Copy link

rusins commented Apr 14, 2021

@advanpix

Ah, I did not notice that. You are correct. The cleanup code now looks sound to me. Must be something else then...

@robol
Copy link
Owner Author

robol commented Apr 15, 2021

Thanks for the effort anyway! I did not have time to look into this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants