decref results of PyStr_FromString
authorNoel Power <noel.power@suse.com>
Wed, 23 Jan 2019 18:08:58 +0000 (18:08 +0000)
committerNoel Power <npower@samba.org>
Thu, 7 Feb 2019 12:44:30 +0000 (13:44 +0100)
Where we create temporary objects (which are added to containers)
these objects already get there ref count incremented. In this case
we need to decref those objects to ensure they are released.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source4/param/provision.c

index 10a657b981be1f8618146056d4cbb7ae2f0c47b3..ebcc0cd77da3b5a41ed431905048bf62be7e1ee4 100644 (file)
 static PyObject *provision_module(void)
 {
        PyObject *name = PyStr_FromString("samba.provision");
+       PyObject *mod = NULL;
        if (name == NULL)
                return NULL;
-       return PyImport_Import(name);
+       mod = PyImport_Import(name);
+       Py_CLEAR(name);
+       return mod;
 }
 
 static PyObject *schema_module(void)
 {
        PyObject *name = PyStr_FromString("samba.schema");
+       PyObject *mod = NULL;
        if (name == NULL)
                return NULL;
-       return PyImport_Import(name);
+       mod = PyImport_Import(name);
+       Py_CLEAR(name);
+       return mod;
 }
 
 static PyObject *ldb_module(void)
 {
        PyObject *name = PyStr_FromString("ldb");
+       PyObject *mod = NULL;
        if (name == NULL)
                return NULL;
-       return PyImport_Import(name);
+       mod = PyImport_Import(name);
+       Py_CLEAR(name);
+       return mod;
 }
 
 static PyObject *PyLdb_FromLdbContext(struct ldb_context *ldb_ctx)