简体   繁体   English

glibc检测到*** free():无效的指针:Python c ++和Swig

[英]glibc detected *** free(): invalid pointer: Python c++ and Swig

I have to run some unit tests which are written in Python. 我必须运行一些用Python编写的单元测试。 We have the code to test in c++, so I compiled it into a shared object and using swig providing an interface for the python scripts to call into the necessary api's to test. 我们有要在c ++中进行测试的代码,因此我将其编译为共享对象,并使用swig为python脚本提供了接口以调用必要的api进行测试。

Now when i run one of the python scripts (it is obviously accessing the c++ codebase which i intend to test), i am getting a "glibc detected free(): invalid pointer". 现在,当我运行一个python脚本(显然正在访问我打算测试的c ++代码库)时,我得到了“ glibc检测到的free():无效指针”。 Now I do understand that there is some memory issue, either a double free or I am freeing an inaccessible memory. 现在,我确实知道存在一些内存问题,可能是两次释放,或者我正在释放无法访问的内存。 Now what i am requesting from you experts: 现在,我向您请专家:

1] I am not getting any backtrace(no line number even), is there anyway to know where the issue is happening? 1]我没有得到任何回溯记录(甚至没有行号),是否有办法知道问题出在哪里? I am not getting any info other than the script stopping abruptly at some point and printing something like this 除了脚本突然停止并打印类似内容外,我没有任何其他信息
*** glibc detected * free(): invalid pointer: 0x099e9b28 *** ***检测到glibc * free():无效的指针:0x099e9b28 ***
Can i get a backtrace somehow? 我能以某种方式获得追溯吗? By setting some flag may be? 通过设置一些标志可能是?

2] I ran valgrind: 2]我跑了valgrind:
"valgrind --leak-check=yes ./myscript.py" “ valgrind --leak-check =是./myscript.py”
I did not get something much, some lines from it: 我没有得到太多,从中得到一些启示:
glibc detected free(): invalid pointer: 0x099e9b28 glibc检测到free():无效的指针:0x099e9b28
==25728== == 25728 ==
==25728== Conditional jump or move depends on uninitialised value(s) == 25728 ==条件跳转或移动取决于未初始化的值
==25728== at 0x625AEA: PyObject_Free (in /usr/lib/libpython2.3.so.1.0) == 25728 ==在0x625AEA:PyObject_Free(在/usr/lib/libpython2.3.so.1.0中)
==25728== by 0x614C7F: (within /usr/lib/libpython2.3.so.1.0) == 25728 ==通过0x614C7F:(在/usr/lib/libpython2.3.so.1.0内)
==25728== by 0x61EA53: (within /usr/lib/libpython2.3.so.1.0) == 25728 ==通过0x61EA53:(在/usr/lib/libpython2.3.so.1.0内)

I am not getting anything related to my code basically. 我基本上没有得到任何与我的代码相关的信息。 So is there something else i should do with valgrind. 所以还有其他我应该用valgrind做的事情。

3] I tried printfs, its taking me to nothing actually. 3]我尝试了printfs,实际上没有任何帮助。
4] I tried gdb: 4]我尝试了gdb:
prompt>gdb python 提示> gdb python
gdb> set args myscript.py gdb>设置参数myscript.py
gdb> run gdb>运行

This runs the script, I could not set any breakpoints, it runs and prints the error. 这将运行脚本,我无法设置任何断点,它将运行并显示错误。 No absolute help. 没有绝对的帮助。 Is there something else i should do with GDB? GDB还有其他我应该做的事情吗? Any way to set breakpoints? 有什么办法设置断点?

Thanks a lot for any kind of pointer you guys can give me. 非常感谢你们给我的任何指针。

I finally figured out! 我终于想通了! I executed the command 我执行了命令
ulimit -c unlimited ulimit -c无限

After this i see a core dump, now i can analyse it via 之后,我看到一个核心转储,现在我可以通过分析它了
gdb /usr/bin/python2.3 core.31685 gdb /usr/bin/python2.3 core.31685

I have successfully debugged this type of problem using Google's heap checker . 我已经使用Google的堆检查器成功调试了此类问题。 It will give you the stack traces both of the point of allocation and deallocation. 它将为您提供分配点和释放点的堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM