sudo_module_register_loghandler: clear sudo_type_LogHandler on error

Also add comments about PyModule_AddObject stealing a ref on success.
This commit is contained in:
Todd C. Miller
2023-07-22 08:33:04 -06:00
parent b52c32f234
commit 0462a4ee8c
4 changed files with 18 additions and 15 deletions

View File

@@ -148,9 +148,12 @@ sudo_module_register_loghandler(PyObject *py_module)
if (sudo_type_LogHandler == NULL)
goto cleanup;
if (PyModule_AddObject(py_module, "LogHandler", sudo_type_LogHandler) < 0)
if (PyModule_AddObject(py_module, "LogHandler", sudo_type_LogHandler) < 0) {
Py_CLEAR(sudo_type_LogHandler);
goto cleanup;
}
// PyModule_AddObject steals a reference to sudo_type_LogHandler on success
Py_INCREF(sudo_type_LogHandler);
cleanup: