Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glibc detected *** python: double free or corruption (!prev) SWIG

Tags:

python

glibc

swig

After writing up a wrapper in SWIG for my C++ algorithms i constantly get this error when I quit the Python interpreter after importing the module:

    $ python
    iPython 2.5.6 (r256:88840, Mar 10 2012, 14:05:15) 
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>from algol import *
    >>> 
    *** glibc detected *** python: double free or corruption (!prev): 0x0000000001e42430 ***

Then I have to Ctrl+C to get back control... what is happening?

I am running the following commands to build up my SWIG wrappers:

$NAME=algol
swig -c++ -python $NAME.i
g++ -fpic -c $NAME.cpp $NAME.hpp $NAME\_wrap.cxx -I/usr/local/include/python2.5
g++ -Xlinker -zmuldefs -shared $NAME.o $NAME\_wrap.o -o _$NAME.so

My swig interface file is just an include of algol.hpp:

%module algol
%{
#include "algol.hpp"
%}
%include "algol.hpp"

What do you think about this? :S

Edit: attached sample source code here -> http://pastebin.com/q210vEAs

like image 988
Cristian Avatar asked Nov 14 '22 05:11

Cristian


1 Answers

what is happening?

Exactly what the message says: either some code performed a double-free, or some other heap corruption.

As suggested by awoodland, run python under Valgrind, and see where that corruption or double-free is happening.

like image 52
Employed Russian Avatar answered Dec 09 '22 11:12

Employed Russian