I'm using Python's CTypes to bind to a shared library; I have a callback registered with this library, which is called in the context of a thread that the library itself creates. I've found that if I call libc.malloc() (libc = cdll.LoadLibrary('libc.so.6')) from within my callback, that it returns bogus values. Not NULL, but an address which will cause a segfault if I dereference it.
Can anyone provide me with any insight to what may be happening, or alternatively, tell me that they call malloc() in the same way, and that it works for them.
Are you properly anottating the malloc call so that ctypes know it should return pointers not integers? (Doubly so if you are working on a 64bit box?)
Malloc failing when called via ctypes from a c thread