summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2009-10-01 13:59:02 +0200
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2009-10-01 13:59:02 +0200
commit54ea150f364f9c39a9f0a2abe5a98e82df62845a (patch)
tree8a51f26bcb4ae8f835abf8b0777945a1e94f6f35 /source4
parente80891db4123a2ae326517c27c559ace18b0f05b (diff)
downloadsamba-54ea150f364f9c39a9f0a2abe5a98e82df62845a.tar.gz
samba-54ea150f364f9c39a9f0a2abe5a98e82df62845a.tar.bz2
samba-54ea150f364f9c39a9f0a2abe5a98e82df62845a.zip
s4:ldb_msg_diff - Fixes up possible memory leaks and the python binding of it
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/common/ldb_msg.c12
-rw-r--r--source4/lib/ldb/pyldb.c4
2 files changed, 13 insertions, 3 deletions
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 702978a361..929f24cd88 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -560,6 +560,9 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
unsigned int i;
mod = ldb_msg_new(ldb);
+ if (mod == NULL) {
+ return NULL;
+ }
mod->dn = msg1->dn;
mod->num_elements = 0;
@@ -567,6 +570,7 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
msg2 = ldb_msg_canonicalize(ldb, msg2);
if (msg2 == NULL) {
+ talloc_free(mod);
return NULL;
}
@@ -581,7 +585,8 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
if (ldb_msg_add(mod,
&msg2->elements[i],
- el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) {
+ el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != LDB_SUCCESS) {
+ talloc_free(mod);
return NULL;
}
}
@@ -589,10 +594,11 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
/* look in msg1 to find elements that need to be deleted */
for (i=0;i<msg1->num_elements;i++) {
el = ldb_msg_find_element(msg2, msg1->elements[i].name);
- if (!el) {
+ if (el == NULL) {
if (ldb_msg_add_empty(mod,
msg1->elements[i].name,
- LDB_FLAG_MOD_DELETE, NULL) != 0) {
+ LDB_FLAG_MOD_DELETE, NULL) != LDB_SUCCESS) {
+ talloc_free(mod);
return NULL;
}
}
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 0fe4da9887..0dac61b8b7 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -956,6 +956,10 @@ static PyObject *py_ldb_msg_diff(PyLdbObject *self, PyObject *args)
}
diff = ldb_msg_diff(PyLdb_AsLdbContext(self), PyLdbMessage_AsMessage(py_msg_old), PyLdbMessage_AsMessage(py_msg_new));
+ if (!diff) {
+ PyErr_SetString(PyExc_KeyError, "Failed to generate the Ldb Message diff");
+ return NULL;
+ }
py_ret = PyLdbMessage_FromMessage(diff);