1. memory leak: ob_refcnt of '*strobj' is 2 too high

    Report

    1
    inline char * get_string(PyObject * uniobj) {
    // TODO: re-evalutate if utf8 is always appropriate here.
    PyObject *strobj = PyUnicode_AsEncodedString(uniobj, "UTF-8", "strict");
    if (!strobj) return NULL;
    Py_INCREF(strobj);
    return PyBytes_AS_STRING(strobj);
    }
    1. when PyUnicodeUCS4_AsEncodedString() succeeds

      '*strobj' was allocated at: PyObject *strobj = PyUnicode_AsEncodedString(uniobj, "UTF-8", "strict");

    2. taking False path

    3. was expecting final owned ob_refcnt of '*strobj' to be 0 since nothing references it but final ob_refcnt is refs: 2 owned