[Python-de] Memory Leaks

Julian Rath julian.rath at gmail.com
Die Jul 12 12:25:14 CEST 2005


Eine Frage:
Verwende ich hier das Py_INCREF richtig?
danke
Julian

PyObject* get_error_str(HRESULT hr)
{
    if(FACILITY_WINDOWS == HRESULT_FACILITY(hr))
        hr = HRESULT_CODE(hr);
    char* pErrMsg;
        PyObject* error;
    if(FormatMessage(
      FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
      NULL,
          hr,
          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
      (LPSTR)&pErrMsg,
          0,
          NULL) != 0)
        {
        error = PyString_FromFormat("[0x%x] %s", hr ,pErrMsg);
        LocalFree(pErrMsg);
    }
        else
                error = PyString_FromFormat("[0x%x] unknown error code", hr);
        Py_INCREF(error);
        return error;
}