From bfc62d8be226876ddfad9d630cee214f98dcc049 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 10 Oct 2022 22:52:33 +0300 Subject: [PATCH] Properly handle module refcount during init errors Together with the commit in #36, this should fix #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; } -- 2.39.5