title: Python ctypes: how to free memory? Getting invalid pointer error
body: <p>I want to get some string from a C/C++ library with ctypes into python. My code looks like this:</p>
  
  <p>Code in lib:</p>
  
  <pre><code>const char* get(struct something *x) 
  {
      [...]
      // buf is a stringstream
     return strdup(buf.str().c_str());
  }
  
  void freeme(char *ptr)
  {
      free(ptr);
  }
  </code></pre>
  
  <p>Python code:</p>
  
  <pre><code>fillprototype(lib.get, c_char_p, POINTER(some_model)])
  fillprototype(lib.freeme, None, [c_char_p])
  
  // what i want to do here: get a string into python so that i can work
  // with it and release the memory in the lib.
  c_str = lib.get(some_model)
  y = ''.join(c_str)
  lib.freeme(c_str) 
  </code></pre>
  
  <p>If i print() c_str, everything is there. Problem is (or seems to be) in the last Python line. I cannot free the memory - the library is getting a wrong pointer. What I am doing wrong here? (And please don't suggest boost::python or so).</p>
  
  <pre><code>*** glibc detected *** python2: munmap_chunk(): invalid pointer: 0x00000000026443fc ***
  </code></pre>