[PyKDE] Memory leak in converstion to std::string & ?

Paul F. Kunz Paul_Kunz at slac.stanford.edu
Fri Aug 13 00:53:58 BST 2004


   I have a C++ class with a method

  virtual void setAutoTicks ( const std::string &,  bool );

 I wrote the ConvertToTypeCode this...


%ConvertToTypeCode
         // Allow a Python string whenever a string is expected.
         if (sipIsErr == NULL)
             return PyString_Check(sipPy);
         if (sipPy == Py_None) {
             *sipCppPtr = NULL;
             return 0;
         }
         if (PyString_Check(sipPy)) {
             *sipCppPtr = new string(PyString_AS_STRING(sipPy));
             return 0;
         }
         *sipCppPtr = (string *)sipForceConvertTo_std_string(sipPy,sipIsErr);
         return 1;
%End

It works, but it leak memory.   One of my users used the method in a
loop so it was called 200,000 times and he reported it leaked about
250 bytes per iteration.   Taking out the string argument and
re-running his test case, showed no leak at all.

   Any ideas?





More information about the PyQt mailing list