I\'m using CFFI to generate a DLL:
import cffi
ffibuilder = cffi.FFI()
ffibuilder.embedding_api(\'\'\'
char* get_str
It is a dangerous practice to allocate in one place and then free across a DLL boundary. Avoid it unless you know that you're doing it right (same CRT version etc.). Thus spake Microsoft:
When you pass C Run-time (CRT) objects such as file handles, locales, and environment variables into or out of a DLL (function calls across the DLL boundary), unexpected behavior can occur if the DLL, as well as the files calling into the DLL, use different copies of the CRT libraries.
A related problem can occur when you allocate memory (either explicitly with new or malloc, or implicitly with strdup, strstreambuf::str, and so on) and then pass a pointer across a DLL boundary to be freed. This can cause a memory access violation or heap corruption if the DLL and its users use different copies of the CRT libraries.
One solution to this is to expose a free
function from your DLL that is turning over an allocated object so the client can call your free
function on it, or in C++ you might use a smart pointer with a custom deleter to do it right.