20.5. Debugging Tactics

So what is the problem that you are trying to solve?

20.5.1. Access After Free

20.5.1.1. Problem

You suspect that you are accessing a Python object after it has been free’d. Code such as this:

static PyObject *access_after_free(PyObject *pModule) {
    PyObject *pA = PyLong_FromLong(1024L);
    Py_DECREF(pA);
    PyObject_Print(pA, stdout, 0);
    Py_RETURN_NONE;
}

pA has been freed before PyObject_Print is called.

20.5.1.2. Solution

Python 3.4.3 (default, Sep 16 2015, 16:56:10)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cPyExtPatt import cPyRefs
>>> cPyRefs.afterFree()
<refcnt -2604246222170760229 at 0x10a474130>
>>>