Python 3.10 added PyModule_AddObjectRef() to more easily avoid a common memory leak when ading to a module fails (unlikely in our case, since we initialize early in the python process, but still something we must worry about for corner-case correctness). But since we target older Python, we must check for errors and clean up ourselves. Fixes: 259d46cb ("python: Raise a custome exception containing error string and errno.", v0.1.6) --- generator/Python.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/generator/Python.ml b/generator/Python.ml index 1c4446e..3f672ba 100644 --- a/generator/Python.ml +++ b/generator/Python.ml @@ -143,9 +143,11 @@ let return NULL; nbd_internal_py_Error = PyErr_NewException (\"nbd.Error\", NULL, NULL); - if (nbd_internal_py_Error == NULL) + if (PyModule_AddObject (mod, \"Error\", nbd_internal_py_Error) < 0) { + Py_XDECREF (nbd_internal_py_Error); + Py_DECREF (mod); return NULL; - PyModule_AddObject (mod, \"Error\", nbd_internal_py_Error); + } return mod; } -- 2.36.1