From 98919e10b776e6e2a6d06a8a6bcceb73b3667c24 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 10 Oct 2022 22:42:34 +0300 Subject: [PATCH] Properly handle module refcount during init errors Together with the commit in #36, this should fix issue #35, --- xattr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xattr.c b/xattr.c index 1cb5088..31ad87f 100644 --- a/xattr.c +++ b/xattr.c @@ -1206,6 +1206,10 @@ PyInit_xattr(void) goto err_out; if((ns_user = PyBytes_FromString("user")) == NULL) goto err_out; + + /* Add the new objects to the module */ + /* TODO: after switching to min 3.10, use the *Ref version, and simplify + the error handling. */ if(PyModule_AddObject(m, "NS_SECURITY", ns_security) < 0) goto err_out; ns_security = NULL; @@ -1226,5 +1230,6 @@ PyInit_xattr(void) Py_XDECREF(ns_trusted); Py_XDECREF(ns_system); Py_XDECREF(ns_security); + Py_DECREF(m); INITERROR; }