From a8e10a12493fdb6b8347b14e157aeb619cf2d2da Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 22 Jan 2019 18:26:23 +0000 Subject: Decrement references to python objects passed to Py_BuildValue Py_BuildValue when processing format 'O' will 'Pass a Python object untouched (except for its reference count, which is incremented by one' Basically this means if you are using a new reference to a PyObject to pass to BuildValue (to be used with the 'O' format) the reference *isn't* stolen so you really do need to DECREF it in order to ensure it gets cleaned up. Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall --- source4/dns_server/pydns.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/dns_server/pydns.c b/source4/dns_server/pydns.c index a4441ddef56..16d22dfe4b8 100644 --- a/source4/dns_server/pydns.c +++ b/source4/dns_server/pydns.c @@ -100,6 +100,7 @@ static PyObject *py_dsdb_dns_lookup(PyObject *self, struct ldb_context *samdb; PyObject *py_ldb, *ret, *pydn; PyObject *py_dns_partition = NULL; + PyObject *result = NULL; char *dns_name; TALLOC_CTX *frame; NTSTATUS status; @@ -156,7 +157,10 @@ static PyObject *py_dsdb_dns_lookup(PyObject *self, ret = py_dnsp_DnssrvRpcRecord_get_list(records, num_records); pydn = pyldb_Dn_FromDn(dn); talloc_free(frame); - return Py_BuildValue("(OO)", pydn, ret); + result = Py_BuildValue("(OO)", pydn, ret); + Py_CLEAR(ret); + Py_CLEAR(pydn); + return result; } static PyObject *py_dsdb_dns_extract(PyObject *self, PyObject *args) -- cgit v1.2.1