mirror of
https://github.com/samba-team/samba.git
synced 2025-02-25 17:57:42 +03:00
Cleanup references to module objects returned from PyImport_ImportModule
Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
parent
1be9b0cf1b
commit
53d973f59c
@ -180,8 +180,10 @@ static PyObject *py_ldb_set_session_info(PyObject *self, PyObject *args)
|
||||
return NULL;
|
||||
|
||||
PyAuthSession_Type = PyObject_GetAttrString(mod_samba_auth, "session_info");
|
||||
if (PyAuthSession_Type == NULL)
|
||||
if (PyAuthSession_Type == NULL) {
|
||||
Py_CLEAR(mod_samba_auth);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = PyArg_ParseTuple(args, "O!", PyAuthSession_Type, &py_session_info);
|
||||
|
||||
@ -262,11 +264,15 @@ MODULE_INIT_FUNC(_ldb)
|
||||
return NULL;
|
||||
|
||||
PySambaLdb.tp_base = (PyTypeObject *)PyObject_GetAttrString(pyldb_module, "Ldb");
|
||||
if (PySambaLdb.tp_base == NULL)
|
||||
if (PySambaLdb.tp_base == NULL) {
|
||||
Py_CLEAR(pyldb_module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
py_ldb_error = PyObject_GetAttrString(pyldb_module, "LdbError");
|
||||
|
||||
Py_CLEAR(pyldb_module);
|
||||
|
||||
if (PyType_Ready(&PySambaLdb) < 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -53,10 +53,13 @@
|
||||
static PyObject *py_ldb_get_exception(void)
|
||||
{
|
||||
PyObject *mod = PyImport_ImportModule("ldb");
|
||||
PyObject *result = NULL;
|
||||
if (mod == NULL)
|
||||
return NULL;
|
||||
|
||||
return PyObject_GetAttrString(mod, "LdbError");
|
||||
result = PyObject_GetAttrString(mod, "LdbError");
|
||||
Py_CLEAR(mod);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
|
||||
@ -741,11 +744,15 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
|
||||
|
||||
py_type = (PyTypeObject *)PyObject_GetAttrString(module, "MessageElement");
|
||||
if (py_type == NULL) {
|
||||
Py_DECREF(module);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_CLEAR(module);
|
||||
|
||||
py_ret = py_type->tp_alloc(py_type, 0);
|
||||
Py_CLEAR(py_type);
|
||||
if (py_ret == NULL) {
|
||||
Py_DECREF(py_type);
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
@ -753,8 +760,7 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
|
||||
|
||||
ret->mem_ctx = talloc_new(NULL);
|
||||
if (talloc_reference(ret->mem_ctx, new_el) == NULL) {
|
||||
Py_DECREF(py_type);
|
||||
Py_DECREF(py_ret);
|
||||
Py_CLEAR(py_ret);
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
@ -40,8 +40,12 @@
|
||||
|
||||
static void PyErr_SetDsExtendedError(enum drsuapi_DsExtendedError ext_err, const char *error_description)
|
||||
{
|
||||
PyObject *error = PyObject_GetAttrString(PyImport_ImportModule("samba"),
|
||||
"DsExtendedError");
|
||||
PyObject *mod = NULL;
|
||||
PyObject *error = NULL;
|
||||
mod = PyImport_ImportModule("samba");
|
||||
if (mod) {
|
||||
error = PyObject_GetAttrString(mod, "DsExtendedError");
|
||||
}
|
||||
if (error_description == NULL) {
|
||||
switch (ext_err) {
|
||||
/* Copied out of ndr_drsuapi.c:ndr_print_drsuapi_DsExtendedError() */
|
||||
@ -98,10 +102,12 @@ static void PyErr_SetDsExtendedError(enum drsuapi_DsExtendedError ext_err, const
|
||||
break;
|
||||
}
|
||||
}
|
||||
PyErr_SetObject(error,
|
||||
if (error) {
|
||||
PyErr_SetObject(error,
|
||||
Py_BuildValue(discard_const_p(char, "(i,s)"),
|
||||
ext_err,
|
||||
error_description));
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *py_net_join_member(py_net_Object *self, PyObject *args, PyObject *kwargs)
|
||||
|
@ -555,16 +555,22 @@ MODULE_INIT_FUNC(base)
|
||||
return NULL;
|
||||
|
||||
BaseObject_Type = (PyTypeObject *)PyObject_GetAttrString(dep_talloc, "BaseObject");
|
||||
if (BaseObject_Type == NULL)
|
||||
if (BaseObject_Type == NULL) {
|
||||
Py_CLEAR(dep_talloc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_CLEAR(dep_talloc);
|
||||
dep_samba_dcerpc_misc = PyImport_ImportModule("samba.dcerpc.misc");
|
||||
if (dep_samba_dcerpc_misc == NULL)
|
||||
if (dep_samba_dcerpc_misc == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ndr_syntax_id_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_misc, "ndr_syntax_id");
|
||||
if (ndr_syntax_id_Type == NULL)
|
||||
Py_CLEAR(dep_samba_dcerpc_misc);
|
||||
if (ndr_syntax_id_Type == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
py_transfer_syntax_ndr_SyntaxType.tp_base = ndr_syntax_id_Type;
|
||||
py_transfer_syntax_ndr_SyntaxType.tp_basicsize = pytalloc_BaseObject_size();
|
||||
@ -576,22 +582,28 @@ MODULE_INIT_FUNC(base)
|
||||
py_dcerpc_ndr_pointer_type.tp_base = BaseObject_Type;
|
||||
py_dcerpc_ndr_pointer_type.tp_basicsize = pytalloc_BaseObject_size();
|
||||
|
||||
if (PyType_Ready(&dcerpc_InterfaceType) < 0)
|
||||
if (PyType_Ready(&dcerpc_InterfaceType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&py_transfer_syntax_ndr_SyntaxType) < 0)
|
||||
if (PyType_Ready(&py_transfer_syntax_ndr_SyntaxType) < 0) {
|
||||
return NULL;
|
||||
if (PyType_Ready(&py_transfer_syntax_ndr64_SyntaxType) < 0)
|
||||
}
|
||||
if (PyType_Ready(&py_transfer_syntax_ndr64_SyntaxType) < 0) {
|
||||
return NULL;
|
||||
if (PyType_Ready(&py_bind_time_features_syntax_SyntaxType) < 0)
|
||||
}
|
||||
if (PyType_Ready(&py_bind_time_features_syntax_SyntaxType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&py_dcerpc_ndr_pointer_type) < 0)
|
||||
if (PyType_Ready(&py_dcerpc_ndr_pointer_type) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m = PyModule_Create(&moduledef);
|
||||
if (m == NULL)
|
||||
if (m == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF((PyObject *)&dcerpc_InterfaceType);
|
||||
PyModule_AddObject(m, "ClientConnection", (PyObject *)&dcerpc_InterfaceType);
|
||||
|
@ -392,6 +392,7 @@ PyObject *py_return_ndr_struct(const char *module_name, const char *type_name,
|
||||
{
|
||||
PyTypeObject *py_type;
|
||||
PyObject *module;
|
||||
PyObject *result = NULL;
|
||||
|
||||
if (r == NULL) {
|
||||
Py_RETURN_NONE;
|
||||
@ -408,7 +409,10 @@ PyObject *py_return_ndr_struct(const char *module_name, const char *type_name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pytalloc_reference_ex(py_type, r_ctx, r);
|
||||
result = pytalloc_reference_ex(py_type, r_ctx, r);
|
||||
Py_CLEAR(module);
|
||||
Py_CLEAR(py_type);
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject *PyString_FromStringOrNULL(const char *str)
|
||||
|
@ -201,19 +201,23 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
|
||||
|
||||
static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
|
||||
{
|
||||
PyObject *mod_security, *dom_sid_Type;
|
||||
PyObject *mod_security = NULL, *dom_sid_Type = NULL, *result = NULL;
|
||||
|
||||
mod_security = PyImport_ImportModule("samba.dcerpc.security");
|
||||
if (mod_security == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dom_sid_Type = PyObject_GetAttrString(mod_security, "dom_sid");
|
||||
if (dom_sid_Type == NULL) {
|
||||
Py_DECREF(mod_security);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = pytalloc_reference((PyTypeObject *)dom_sid_Type, sid);
|
||||
Py_DECREF(mod_security);
|
||||
return pytalloc_reference((PyTypeObject *)dom_sid_Type, sid);
|
||||
Py_DECREF(dom_sid_Type);
|
||||
return result;
|
||||
}
|
||||
|
||||
NTSTATUS provision_store_self_join(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
|
||||
|
Loading…
x
Reference in New Issue
Block a user