-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Memory leak in function is_scalar_with_conversion
(a static analysis report with a POC)
#19376
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
Comments
is_scalar_with_conversion
(a static analysis report)is_scalar_with_conversion
(a static analysis report with POC)
is_scalar_with_conversion
(a static analysis report with POC)is_scalar_with_conversion
(a static analysis report with a POC)
Hello @Snape3058, @seberg, I was trying to understand this issue and i think that based on https://stackoverflow.com/questions/24444667/what-is-the-purpose-of-py-decref-and-py-incref that a Py_DECREF(value) after val = PyLong_AsSsize_t(value); would solve the issue. Could you please maybe give more hints because i have not contribute in numpy project before? |
This is the Python C-API. Basically, you "just" need to count how often you "own" an object, and make sure you own it 0 times when you are done – but I know it can be very confusing when you start with the Python C-API.
Most functions return new references, so you do not have to call One thing if you fix this is to please also add the reproducer as a test. It is OK if the test just runs the bad code path: There are tools to do reference count leak checking, we do not have to test it explicitly in the test suite. (It would be fine to do that, but I think it is not worth the trouble probably) |
Hello @seberg, I opened #19403 and i checked that it passes the assert from code snippet above.
Running for exampe python runtests.py -t numpy/core/tests though does not work for me(see build.log). Could you please advice how to proceed or whom to ask? I tried to ask about it in stack overflow but i did not get any reply. Also my os is windows. |
Did you run |
Hello @mattip, |
I asked because the top line is "numpy/random_bounded_integers.pxd.in has not changed" which indicates your build is not clean. |
On the other hand, it may just be a bug with windows + conda fortran compiler with a clean environment (before calling
before running |
build.log |
@rgommers does the |
It shouldn't, Let me copy the build log here, it's short:
It can't find a BLAS library. The problem is that |
Oh wait, there's a second one, ending in
@theoniko you can include it directly here, and if it's long then enclose it in:
Much easier than letting us download build logs. |
I'm not a Windows expert, but that doesn't seem healthy. There's nothing useful to include there, and perhaps causes the error? I'd say just do what conda-forge |
I used ubuntu VM and i was finally able to run the unit tests. I will make a new try for Windows. Is there a compiler flag to try gcc instead of VS compiler? |
Hello @rgommers, @mattip, @seberg
|
Somehow you installed |
Reproducing code example:
As the reference count linearly increases with the number of invocations, which indicates a memory leak.
Error message:
The path provided by the static analyzer is as follows.
In condition branch starts from here.
numpy/numpy/core/src/multiarray/number.c
Line 422 in 04ab04d
A new reference returned from
PyNumber_Index
and pointed to bevalue
.numpy/numpy/core/src/multiarray/number.c
Line 423 in 04ab04d
Assume
value
is notNULL
.numpy/numpy/core/src/multiarray/number.c
Line 425 in 04ab04d
Call
PyLong_AsSsize_t
withvalue
, which does not steal the reference.numpy/numpy/core/src/multiarray/number.c
Line 431 in 04ab04d
Function returns on the normal branch. (the error branch is also the same case)
numpy/numpy/core/src/multiarray/number.c
Line 437 in 04ab04d
The new reference pointed to by
value
leaks without decreasing its refcnt.NumPy/Python version information:
Static analysis carried out on commit 04ab04d.
The text was updated successfully, but these errors were encountered: