How to debug - Python CTypes calling glibc * detection
I have compiled the C ++ program into a dynamic library which I now call in python via ctypes. However, I am getting the following error:
*** glibc detected *** ../../bin/python: free(): invalid pointer: 0x00007fbdf8ae3500 ***
How can I tell if this is a bug in the C ++ code or how am I using ctypes?
The C ++ library works successfully when linked with a C program, or if I compile it as a standalone program. Combined with ctypes, it always fails on this C ++ line:
// ... A bunch of code
if(tempBuffer) {
delete[] tempBuffer;
// More code below that never runs...
Failed to execute Python code:
def test(fileName):
feedbackLib = cdll.LoadLibrary("./libpitch.so")
# Set return type to a character pointer
feedbackLib.getPitchString.restype = c_char_p
feedbackLib.getPitchString.argtypes = [c_char_p]
# Crashes Here!
feedbackStr = feedbackLib.getPitchString(fileName)
return feedbackStr
For some reason, I can get the python program to work successfully if I change things like this:
def test(fileName):
# I've only changed this line
feedbackLib = CDLL("./libpitch.so")
# Set return type to a character pointer
feedbackLib.getPitchString.restype = c_char_p
feedbackLib.getPitchString.argtypes = [c_char_p]
# No longer crashes!
feedbackStr = feedbackLib.getPitchString(fileName)
return feedbackStr
However, if I start adding things to the above function (which I need to do) it gives me other glibc errors.
Here's information on how I compiled C ++ in case it matters.
The header of the function I am calling using extern "C" looks like how to get the C ++ code to work with CTypes:
extern "C" char* getPitchString(char* filename);
Commands g ++:
$(CXX) $(LDFLAGS) -fPIC -c $(SRCS) $(LIBS) $(CXX) -shared -Wl,-soname,libpitch.so -o libpitch.so $(OBJS) $(LIBS)
source to share