Fix mem leak with PyBytes_FromStringAndSize
authorNoel Power <noel.power@suse.com>
Mon, 28 Jan 2019 15:23:48 +0000 (15:23 +0000)
committerNoel Power <npower@samba.org>
Wed, 13 Feb 2019 10:42:08 +0000 (11:42 +0100)
Reviewed-by: Andrew Bartlett abartlet@samba.org
source4/auth/gensec/pygensec.c

index d8f782f8d191138eae85995f43915cf641a73fe7..72981a22263e0f31f4a3f7336f9cb6bd919ffd35 100644 (file)
@@ -453,7 +453,7 @@ static PyObject *py_gensec_update(PyObject *self, PyObject *args)
        NTSTATUS status;
        TALLOC_CTX *mem_ctx;
        DATA_BLOB in, out;
-       PyObject *ret, *py_in;
+       PyObject *py_bytes, *result, *py_in;
        struct gensec_security *security = pytalloc_get_type(self, struct gensec_security);
        PyObject *finished_processing;
 
@@ -477,7 +477,8 @@ static PyObject *py_gensec_update(PyObject *self, PyObject *args)
                talloc_free(mem_ctx);
                return NULL;
        }
-       ret = PyBytes_FromStringAndSize((const char *)out.data, out.length);
+       py_bytes = PyBytes_FromStringAndSize((const char *)out.data,
+                                            out.length);
        talloc_free(mem_ctx);
 
        if (NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
@@ -486,7 +487,9 @@ static PyObject *py_gensec_update(PyObject *self, PyObject *args)
                finished_processing = Py_True;
        }
 
-       return PyTuple_Pack(2, finished_processing, ret);
+       result = PyTuple_Pack(2, finished_processing, py_bytes);
+       Py_XDECREF(py_bytes);
+       return result;
 }
 
 static PyObject *py_gensec_wrap(PyObject *self, PyObject *args)