summaryrefslogtreecommitdiff
path: root/libgpo/pygpo.c
diff options
context:
space:
mode:
authorKristján Valur <kristjan@rvx.is>2019-02-27 16:48:39 +0000
committerNoel Power <npower@samba.org>2019-03-07 14:08:22 +0000
commit18638535044e7ce8589c0288c43de90bf1853d5f (patch)
tree8b005a5cb4cf46c839d9c99790e9edca8d95a008 /libgpo/pygpo.c
parentd2a75489477a6628662e7bb5dd94b3e769e8c3b1 (diff)
downloadsamba-18638535044e7ce8589c0288c43de90bf1853d5f.tar.gz
pygpo: Fix module initialization.
* 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 <kristjan@rvx.is> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Noel Power <npower@samba.org>
Diffstat (limited to 'libgpo/pygpo.c')
-rw-r--r--libgpo/pygpo.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c
index 36e5f1052d0..a8f5613ee43 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;
}