s4/param: Fix provision_get_schema leaking python object
authorNoel Power <noel.power@suse.com>
Fri, 15 Feb 2019 10:04:23 +0000 (10:04 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 21 Feb 2019 03:09:19 +0000 (04:09 +0100)
provision_get_schema returns a ldb_context object which is stored
in a python object. As a result the parent python object is never
decrefed and probably not released ever.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/schema/tests/schema_syntax.c
source4/libnet/libnet_vampire.c
source4/param/provision.c

index 17e62010e70d3f0f805ea55f390d090a3d036403..b22e110db52dc18f01e1fd0484f618052738b737 100644 (file)
@@ -225,6 +225,7 @@ static bool torture_dsdb_syntax_tcase_teardown(struct torture_context *tctx, voi
        struct torture_dsdb_syntax *priv;
 
        priv = talloc_get_type_abort(data, struct torture_dsdb_syntax);
+       talloc_unlink(priv, priv->ldb);
        talloc_free(priv);
 
        return true;
index 6167493c359efa8f35481cc5aac4946b13ae541b..6374946244e78566cdcaf9585d5796acc8f93442 100644 (file)
@@ -337,7 +337,7 @@ static WERROR libnet_vampire_cb_apply_schema(struct libnet_vampire_cb_state *s,
                        DEBUG(0,("Failed to attach schema from local provision using remote prefixMap."));
                        return WERR_INTERNAL_ERROR;
                }
-               talloc_free(schema_ldb);
+               talloc_unlink(s, schema_ldb);
        }
 
        cycle_before_switching = lpcfg_parm_long(s->lp_ctx, NULL,
index 47f296afcdd023d9f1e679ace070a420e0635443..85671f80b87586fd60cd0cecc0e844b54c8749e8 100644 (file)
@@ -555,13 +555,9 @@ struct ldb_context *provision_get_schema(TALLOC_CTX *mem_ctx,
        py_ldb = PyObject_GetAttrString(py_result, "ldb");
        Py_DECREF(py_result);
        ldb_result = pyldb_Ldb_AsLdbContext(py_ldb);
-       /*
-        * #TODO #FIXME There is a leak here !!!
-        * Looks like ldb is a new object returned from schema_fn
-        * We extract the ldb_ctx from that which rightly
-        * will be destoryed when py_ldb is decremented.
-        * Presently the ldb_context is returned (but the owning
-        * object is leaked)
-       */
+       if (talloc_reference(mem_ctx, ldb_result) == NULL) {
+               ldb_result = NULL;
+       }
+       Py_DECREF(py_ldb);
        return ldb_result;
 }