microsoft/picologging

Fix all leaky PyUnicode_FromString uses

Closed this issue · 0 comments

Found multiple cases of call methods/functions where the argument is a string, but the string references is left dangling.

For example

PyObject* s = PyObject_CallMethod_NOARGS(sio, PyUnicode_FromString("getvalue"));

Should be:

PyObject *getvalue_str =  PyUnicode_FromString("getvalue");
PyObject* s = PyObject_CallMethod_NOARGS(sio, getvalue_str);
Py_XDECREF(getvalue_str);

Alternatively, use const strings in the type, as seen in multiple cases for efficiency where you don't need to keep converting back.