diff options
author | Noel Power <noel.power@suse.com> | 2019-01-23 15:15:07 +0000 |
---|---|---|
committer | Noel Power <npower@samba.org> | 2019-02-07 13:44:30 +0100 |
commit | 53d973f59c3514f9c288cc8e53a682176a5fc415 (patch) | |
tree | 99b0ff693f19501d46585f76533ec50dec769fa8 /source4/librpc | |
parent | 1be9b0cf1bc95715e83c27eabecbd4fa2022530b (diff) | |
download | samba-53d973f59c3514f9c288cc8e53a682176a5fc415.tar.gz |
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>
Diffstat (limited to 'source4/librpc')
-rw-r--r-- | source4/librpc/rpc/pyrpc.c | 30 | ||||
-rw-r--r-- | source4/librpc/rpc/pyrpc_util.c | 6 |
2 files changed, 26 insertions, 10 deletions
diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index bcbd94714d0..e00318a96be 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -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); diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c index 6dadc214ea5..29fd281f54d 100644 --- a/source4/librpc/rpc/pyrpc_util.c +++ b/source4/librpc/rpc/pyrpc_util.c @@ -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) |