[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha8-239-gf45a9d6
Andrew Bartlett
abartlet at samba.org
Sun Jul 5 23:51:47 GMT 2009
The branch, master has been updated
via f45a9d63e5a1697a7e85b123b535d2dc05f9fd8c (commit)
via da45d5215d1da2a1ff1b72b9bc3f10ec2192fba9 (commit)
from 880c286bc92db809553c5af2c4a26fe34d6a58dc (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit f45a9d63e5a1697a7e85b123b535d2dc05f9fd8c
Author: Andrew Bartlett <abartlet at samba.org>
Date: Mon Jul 6 09:31:38 2009 +1000
s4:ldb Rework use of talloc and ldif objects in python wrapper
The talloc hirarchy here was a bit odd - we would both steal the
parsed ldif onto 'NULL', then reference it onto a python talloc
wrapper.
Now we just leave the reference, after we complete building the object.
Andrew Bartlett
commit da45d5215d1da2a1ff1b72b9bc3f10ec2192fba9
Author: Andrew Bartlett <abartlet at samba.org>
Date: Mon Jul 6 09:24:18 2009 +1000
s4:ldb Fix talloc hirarchy in LDIF parsing code
The problem here was that some parts of the ldb_message were still
attached to the ldb_ldif structure, and when only the message was
taken (and the ldif free'ed to reclaim memory) we refereced free'ed
memory.
Andrew Bartlett
-----------------------------------------------------------------------
Summary of changes:
source4/lib/ldb/common/ldb_ldif.c | 6 +++---
source4/lib/ldb/pyldb.c | 21 ++++++++++++++++++---
2 files changed, 21 insertions(+), 6 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index 400fb35..d64a9f1 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -632,7 +632,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
if (!el->values) {
goto failed;
}
- ret = a->syntax->ldif_read_fn(ldb, ldif, &value, &el->values[el->num_values]);
+ ret = a->syntax->ldif_read_fn(ldb, el->values, &value, &el->values[el->num_values]);
if (ret != 0) {
goto failed;
}
@@ -647,7 +647,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
el->num_values++;
} else {
/* its a new attribute */
- msg->elements = talloc_realloc(ldif, msg->elements,
+ msg->elements = talloc_realloc(msg, msg->elements,
struct ldb_message_element,
msg->num_elements+1);
if (!msg->elements) {
@@ -661,7 +661,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
goto failed;
}
el->num_values = 1;
- ret = a->syntax->ldif_read_fn(ldb, ldif, &value, &el->values[0]);
+ ret = a->syntax->ldif_read_fn(ldb, el->values, &value, &el->values[0]);
if (ret != 0) {
goto failed;
}
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 9bdd71d..2e0f4fd 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -790,7 +790,6 @@ static PyObject *ldb_ldif_to_pyobject(struct ldb_ldif *ldif)
Py_RETURN_NONE;
} else {
/* We don't want this attached to the 'ldb' any more */
- talloc_steal(NULL, ldif);
return Py_BuildValue(discard_const_p(char, "(iO)"),
ldif->changetype,
PyLdbMessage_FromMessage(ldif->msg));
@@ -804,13 +803,29 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args)
struct ldb_ldif *ldif;
const char *s;
+ TALLOC_CTX *mem_ctx;
+
if (!PyArg_ParseTuple(args, "s", &s))
return NULL;
+ mem_ctx = talloc_new(NULL);
+ if (!mem_ctx) {
+ Py_RETURN_NONE;
+ }
+
list = PyList_New(0);
- while ((ldif = ldb_ldif_read_string(self->ldb_ctx, &s)) != NULL) {
- PyList_Append(list, ldb_ldif_to_pyobject(ldif));
+ while (s && *s != '\0') {
+ ldif = ldb_ldif_read_string(self->ldb_ctx, &s);
+ talloc_steal(mem_ctx, ldif);
+ if (ldif) {
+ PyList_Append(list, ldb_ldif_to_pyobject(ldif));
+ } else {
+ PyErr_SetString(PyExc_ValueError, "unable to parse ldif string");
+ talloc_free(mem_ctx);
+ return NULL;
+ }
}
+ talloc_free(mem_ctx); /* The pyobject already has a reference to the things it needs */
return PyObject_GetIter(list);
}
--
Samba Shared Repository
More information about the samba-cvs
mailing list