title: How to manage string memory with python ctypes
body: <p>My python code is calling a C function in a native library (also written by me). The function takes two strings as arguments and returns its response as a string. The two argument strings that python passes to C library are only read by the C library, so I am not worried about their memory management. AFAIK, their memory will be allocated by python and will be released when the python runtime seems it appropriate. </p>
  
  <p>However, I understand that the memory of the string that C library returns has to be managed explicitly. One way I can implement it is: the C function callocs a character array, populates it with answer and returns from the function. The python code uses the returned string and should call libc's free on that string or call another function of the same C library which will take care of freeing the memory. </p>
  
  <p>Is there any other way to do this? Does ctype offer any utility functions that simplify releasing the memory of data structures returned by native libraries?</p>