summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2010-07-15 14:00:48 +1000
committerAndrew Bartlett <abartlet@samba.org>2010-07-15 22:08:22 +1000
commitfcdf619b361b9c30b59f65ba38f69f344b4c95ae (patch)
tree41b1099c43cc50f290e1367cd6e5338b591b90d0 /source4/lib/ldb
parent5d61b477c66dce60d8ea37081f0c7394c77e1867 (diff)
downloadsamba-fcdf619b361b9c30b59f65ba38f69f344b4c95ae.tar.gz
samba-fcdf619b361b9c30b59f65ba38f69f344b4c95ae.tar.bz2
samba-fcdf619b361b9c30b59f65ba38f69f344b4c95ae.zip
s4:pyldb Fix memory handling for ldb_message_element
The problem here is that we need to use the array, not the individual message element as the memory context. Andrew Bartlett
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/pyldb.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index f1a02c90b1..bcfbedd962 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -1658,9 +1658,14 @@ struct ldb_message_element *PyObject_AsMessageElement(TALLOC_CTX *mem_ctx,
{
struct ldb_message_element *me;
- if (PyLdbMessageElement_Check(set_obj))
- return talloc_reference(mem_ctx,
- PyLdbMessageElement_AsMessageElement(set_obj));
+ if (PyLdbMessageElement_Check(set_obj)) {
+ PyLdbMessageElementObject *set_obj_as_me = (PyLdbMessageElementObject *)set_obj;
+ /* We have to talloc_reference() the memory context, not the pointer which may not actually be it's own context */
+ if (talloc_reference(mem_ctx, set_obj_as_me->mem_ctx)) {
+ return PyLdbMessageElement_AsMessageElement(set_obj);
+ }
+ return NULL;
+ }
me = talloc(mem_ctx, struct ldb_message_element);
@@ -1964,7 +1969,7 @@ static PyObject *py_ldb_msg_getitem_helper(PyLdbMessageObject *self, PyObject *p
if (el == NULL) {
return NULL;
}
- return (PyObject *)PyLdbMessageElement_FromMessageElement(el, msg);
+ return (PyObject *)PyLdbMessageElement_FromMessageElement(el, msg->elements);
}
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
@@ -2003,7 +2008,7 @@ static PyObject *py_ldb_msg_items(PyLdbMessageObject *self)
j++;
}
for (i = 0; i < msg->num_elements; i++, j++) {
- PyList_SetItem(l, j, Py_BuildValue("(sO)", msg->elements[i].name, PyLdbMessageElement_FromMessageElement(&msg->elements[i], self->msg)));
+ PyList_SetItem(l, j, Py_BuildValue("(sO)", msg->elements[i].name, PyLdbMessageElement_FromMessageElement(&msg->elements[i], msg->elements)));
}
return l;
}