From 18638535044e7ce8589c0288c43de90bf1853d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur?= Date: Wed, 27 Feb 2019 16:48:39 +0000 Subject: [PATCH] pygpo: Fix module initialization. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add reference count to type. * Add error checking. * Remove unnecessary tp_new method. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13822 Signed-off-by: Kristján Valur Jónsson Reviewed-by: Andrew Bartlett Reviewed-by: Noel Power --- libgpo/pygpo.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index 36e5f1052d0d..a8f5613ee437 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -143,13 +143,6 @@ static void py_ads_dealloc(ADS* self) Py_TYPE(self)->tp_free((PyObject*)self); } -static PyObject* py_ads_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - ADS *self; - self = (ADS*)type->tp_alloc(type, 0); - return (PyObject*)self; -} - static PyObject* py_ads_connect(ADS *self); static int py_ads_init(ADS *self, PyObject *args, PyObject *kwds) { @@ -496,7 +489,6 @@ static PyTypeObject ads_ADSType = { .tp_doc = "ADS struct", .tp_methods = ADS_methods, .tp_init = (initproc)py_ads_init, - .tp_new = py_ads_new, }; static PyMethodDef py_gpo_methods[] = { @@ -526,25 +518,36 @@ MODULE_INIT_FUNC(gpo) /* Instantiate the types */ m = PyModule_Create(&moduledef); if (m == NULL) { - return m; + goto err; } - PyModule_AddObject(m, "version", - PyStr_FromString(SAMBA_VERSION_STRING)); + if (PyModule_AddObject(m, "version", + PyStr_FromString(SAMBA_VERSION_STRING)) ) { + goto err; + } + ads_ADSType.tp_new = PyType_GenericNew; if (PyType_Ready(&ads_ADSType) < 0) { - return m; + goto err; } - PyModule_AddObject(m, "ADS_STRUCT", (PyObject *)&ads_ADSType); + Py_INCREF(&ads_ADSType); + if (PyModule_AddObject(m, "ADS_STRUCT", (PyObject *)&ads_ADSType)) { + goto err; + } if (pytalloc_BaseObject_PyType_Ready(&GPOType) < 0) { - return m; + goto err; } Py_INCREF((PyObject *)(void *)&GPOType); - PyModule_AddObject(m, "GROUP_POLICY_OBJECT", - (PyObject *)&GPOType); + if (PyModule_AddObject(m, "GROUP_POLICY_OBJECT", + (PyObject *)&GPOType)) { + goto err; + } return m; +err: + Py_CLEAR(m); + return NULL; }