svn commit: samba r26631 - in branches/SAMBA_4_0: . source/lib/ldb
jelmer at samba.org
jelmer at samba.org
Sun Dec 30 16:46:14 GMT 2007
Author: jelmer
Date: 2007-12-30 16:46:14 +0000 (Sun, 30 Dec 2007)
New Revision: 26631
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=26631
Log:
ldb/python: Fix missing elements bug and memory leak.
* Don't increase the PyDict_Next() counter - Python already does that for us.
* Fix a talloc(NULL, ...) memory leak in the code that constructed ldb message
elements.
Modified:
branches/SAMBA_4_0/
branches/SAMBA_4_0/source/lib/ldb/ldb.i
branches/SAMBA_4_0/source/lib/ldb/ldb_wrap.c
Changeset:
Property changes on: branches/SAMBA_4_0
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb.i
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb.i 2007-12-30 16:46:05 UTC (rev 26630)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb.i 2007-12-30 16:46:14 UTC (rev 26631)
@@ -208,10 +208,11 @@
return ret;
}
-ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags,
+ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx,
+ PyObject *set_obj, int flags,
const char *attr_name)
{
- struct ldb_message_element *me = talloc(NULL, struct ldb_message_element);
+ struct ldb_message_element *me = talloc(mem_ctx, struct ldb_message_element);
me->name = attr_name;
me->flags = flags;
if (PyString_Check(set_obj)) {
@@ -275,7 +276,7 @@
ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL)
{
- return ldb_msg_element_from_pyobject(set_obj, flags, name);
+ return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name);
}
#endif
~ldb_msg_element() { talloc_free($self); }
@@ -350,7 +351,7 @@
void __setitem__(const char *attr_name, PyObject *val)
{
- struct ldb_message_element *el = ldb_msg_element_from_pyobject(
+ struct ldb_message_element *el = ldb_msg_element_from_pyobject(NULL,
val, 0, attr_name);
talloc_steal($self, el);
ldb_msg_remove_attr($self, attr_name);
@@ -486,8 +487,7 @@
ldb_msg *msg = NULL;
if (PyDict_Check(py_msg)) {
msg = ldb_msg_new(NULL);
- msg->num_elements = PyDict_Size(py_msg) - 1; /* dn isn't in there */
- msg->elements = talloc_zero_array(msg, struct ldb_message_element, msg->num_elements+1);
+ msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg));
msg_pos = dict_pos = 0;
while (PyDict_Next(py_msg, &dict_pos, &key, &value)) {
if (!strcmp(PyString_AsString(key), "dn")) {
@@ -495,17 +495,22 @@
return LDB_ERR_OTHER;
}
} else {
- msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key));
+ msgel = ldb_msg_element_from_pyobject(msg->elements, value, 0, PyString_AsString(key));
+ if (msgel == NULL) {
+ SWIG_exception(SWIG_TypeError, "unable to import element");
+ return LDB_ERR_OTHER;
+ }
memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel));
msg_pos++;
}
- dict_pos++;
}
if (msg->dn == NULL) {
SWIG_exception(SWIG_TypeError, "no dn set");
return LDB_ERR_OTHER;
}
+
+ msg->num_elements = msg_pos;
} else {
if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0)
return LDB_ERR_OTHER;
Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_wrap.c 2007-12-30 16:46:05 UTC (rev 26630)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_wrap.c 2007-12-30 16:46:14 UTC (rev 26631)
@@ -2687,10 +2687,11 @@
return ret;
}
-ldb_msg_element *ldb_msg_element_from_pyobject(PyObject *set_obj, int flags,
+ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx,
+ PyObject *set_obj, int flags,
const char *attr_name)
{
- struct ldb_message_element *me = talloc(NULL, struct ldb_message_element);
+ struct ldb_message_element *me = talloc(mem_ctx, struct ldb_message_element);
me->name = attr_name;
me->flags = flags;
if (PyString_Check(set_obj)) {
@@ -2886,7 +2887,7 @@
}
SWIGINTERN ldb_msg_element *new_ldb_msg_element(PyObject *set_obj,int flags,char const *name){
- return ldb_msg_element_from_pyobject(set_obj, flags, name);
+ return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name);
}
SWIGINTERN void delete_ldb_msg_element(ldb_msg_element *self){ talloc_free(self); }
@@ -2918,7 +2919,7 @@
ldb_msg_add(self, el, val->flags);
}
SWIGINTERN void ldb_msg___setitem____SWIG_1(ldb_msg *self,char const *attr_name,PyObject *val){
- struct ldb_message_element *el = ldb_msg_element_from_pyobject(
+ struct ldb_message_element *el = ldb_msg_element_from_pyobject(NULL,
val, 0, attr_name);
talloc_steal(self, el);
ldb_msg_remove_attr(self, attr_name);
@@ -3041,8 +3042,7 @@
ldb_msg *msg = NULL;
if (PyDict_Check(py_msg)) {
msg = ldb_msg_new(NULL);
- msg->num_elements = PyDict_Size(py_msg) - 1; /* dn isn't in there */
- msg->elements = talloc_zero_array(msg, struct ldb_message_element, msg->num_elements+1);
+ msg->elements = talloc_zero_array(msg, struct ldb_message_element, PyDict_Size(py_msg));
msg_pos = dict_pos = 0;
while (PyDict_Next(py_msg, &dict_pos, &key, &value)) {
if (!strcmp(PyString_AsString(key), "dn")) {
@@ -3050,17 +3050,22 @@
return 80;
}
} else {
- msgel = ldb_msg_element_from_pyobject(value, 0, PyString_AsString(key));
+ msgel = ldb_msg_element_from_pyobject(msg->elements, value, 0, PyString_AsString(key));
+ if (msgel == NULL) {
+ SWIG_exception(SWIG_TypeError, "unable to import element");
+ return 80;
+ }
memcpy(&msg->elements[msg_pos], msgel, sizeof(*msgel));
msg_pos++;
}
- dict_pos++;
}
if (msg->dn == NULL) {
SWIG_exception(SWIG_TypeError, "no dn set");
return 80;
}
+
+ msg->num_elements = msg_pos;
} else {
if (SWIG_ConvertPtr(py_msg, (void **)&msg, SWIGTYPE_p_ldb_message, 0) != 0)
return 80;
More information about the samba-cvs
mailing list