s4-pydsdb: Use local memory context in py_dsdb_get_oid_from_attid()
authorKamen Mazdrashki <kamenim@samba.org>
Mon, 20 Dec 2010 09:39:26 +0000 (11:39 +0200)
committerKamen Mazdrashki <kamenim@samba.org>
Mon, 20 Dec 2010 09:40:10 +0000 (11:40 +0200)
This version reverts changes from commit b974966cc2b4d0b5b0d83206070b5f7c5c6495d1
and is what Matthieu Patou had commited in d784ecec555a3d9737e6f4b3894f27904d2b833c
with added reference to the schema cache.

I think referencing schema here is the right thing to be done
as thus we garantee that schema cache will stay in memory
for the time our function is executed

source4/dsdb/pydsdb.c

index af035042e641ddbbb8e6a5099c60af99d65429e6..1a51b86455483356a18b60396bf01bc575c5b9b4 100644 (file)
@@ -249,25 +249,37 @@ static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
        const char *oid;
        PyObject *ret;
        WERROR status;
        const char *oid;
        PyObject *ret;
        WERROR status;
+       TALLOC_CTX *mem_ctx;
 
        if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
                return NULL;
 
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
 
 
        if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
                return NULL;
 
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
 
-       schema = dsdb_get_schema(ldb, NULL);
+       mem_ctx = talloc_new(NULL);
+       if (!mem_ctx) {
+               PyErr_NoMemory();
+               return NULL;
+       }
 
 
+       schema = dsdb_get_schema(ldb, mem_ctx);
        if (!schema) {
                PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
        if (!schema) {
                PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
+               talloc_free(mem_ctx);
                return NULL;
        }
        
        status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
                return NULL;
        }
        
        status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
-                                               NULL, &oid);
-       PyErr_WERROR_IS_ERR_RAISE(status);
+                                               mem_ctx, &oid);
+       if (!W_ERROR_IS_OK(status)) {
+               PyErr_SetWERROR(status);
+               talloc_free(mem_ctx);
+               return NULL;
+       }
 
        ret = PyString_FromString(oid);
 
        ret = PyString_FromString(oid);
-       talloc_free(discard_const_p(char, oid));
+
+       talloc_free(mem_ctx);
 
        return ret;
 }
 
        return ret;
 }