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

valgrind is detecting memory leaks in python code #98

Open
AwaisPF opened this issue Jun 22, 2023 · 1 comment
Open

valgrind is detecting memory leaks in python code #98

AwaisPF opened this issue Jun 22, 2023 · 1 comment

Comments

@AwaisPF
Copy link

AwaisPF commented Jun 22, 2023

Even i ran simple cpp file with valgrind having belllow code

#include "Python.h"
#include "iostream"

using namespace std;

int main(){
    setenv("PYTHONPATH",".",1);
    Py_Initialize();
    cout <<"Hello\n";
    Py_Finalize();

}

got bellow errors on valgring.

==140416==    by 0x49F424B: Py_InitializeEx (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x1091ED: main (in /additional_drive/nist/frvt_onnx_sequential/11/test_mem)
==140416==  Address 0x5387020 is 1,520 bytes inside a block of size 2,208 free'd
==140416==    at 0x483CA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==140416==    by 0x4ACD397: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4AC9E1F: PyDict_SetDefault (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4A62DFF: PyUnicode_InternInPlace (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4A62E90: PyUnicode_InternFromString (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4AFC4C1: PyDescr_NewMethod (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x48E34AA: PyType_Ready (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4AB8E04: _PyTypes_Init (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x49F3A6A: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x49F41A2: Py_InitializeFromConfig (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x49F424B: Py_InitializeEx (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x1091ED: main (in /additional_drive/nist/frvt_onnx_sequential/11/test_mem)
==140416==  Block was alloc'd at
...
...
...
==140416==  Block was alloc'd at
==140416==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==140416==    by 0x4AB69E7: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4B20CB7: PyGrammar_AddAccelerators (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4B23184: PyParser_New (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4B26DD2: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x49E79DA: PyParser_ASTFromStringObject (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x49E8387: PyRun_StringFlags (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4A2BADF: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x4ABB546: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x48D0D6C: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x48D246C: _PyEval_EvalFrameDefault (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416==    by 0x48DC06A: ??? (in /usr/lib/x86_64-linux-gnu/libpython3.8.so.1.0)
==140416== 
==140416== ERROR SUMMARY: 898 errors from 107 contexts (suppressed: 0 from 0)

but without vargind there are no errors please suggest me do I need to resolve these errors as nist suggest and replied that I have to fix memory leakage issue
BTW I am applieng for NIST_11 challenge every thing is working fine but memory leakage is the problem and I have on google and found out that python by default does that and it own garbage collector frees memory and may that is why valgrind unable to detect that.

@AwaisPF
Copy link
Author

AwaisPF commented Jun 22, 2023

@mlngan can you please help me to solve this issue

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

1 participant