Serhiy Storchaka added the comment: Idiomatic code is
if (PyModule_AddObject(module, "name", create_new_object()) < 0) goto error; If you already have a reference and need to use it later: obj = create_new_object(); ... /* use obj */ Py_INCREF(); if (PyModule_AddObject(module, "name", create_new_object()) < 0) goto error; ... /* use obj */ Py_DECREF(obj); error: Py_XDECREF(obj); Many current code use above idioms, but it doesn't work as expected. It is almost impossible to write correct code with current behavior. And _decimal.c is not an exception, it has leaks. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26871> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com