- if (PyTuple_SetItem(py_args, 0, py_value) != 0) {
- PyErr_Print();
- Py_DECREF(py_value);
- Py_DECREF(py_args);
- Py_DECREF(py_func);
- Py_DECREF(py_mod);
- return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
+ /*
+ * IMPORTANT: PyTuple_SetItem() "steals" a reference to py_value!
+ * That means we are no longer responsible for Py_XDECREF()'ing it.
+ * It will automatically be free'd when the 'py_args' tuple is free'd.
+ */
+ if (PyTuple_SetItem(py_args, 0, py_value) != 0) { /* STEAL */
+ ret = SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
+ Py_XDECREF(py_value); /* TODO: Ref. stolen upon error? */
+ goto err_run_decref_args;