[SCM] Samba Shared Repository - branch master updated - tevent-0-9-8-833-g54ea150

2009-10-01 Thread Matthias Dieter Wallnöfer
The branch, master has been updated
   via  54ea150f364f9c39a9f0a2abe5a98e82df62845a (commit)
  from  e80891db4123a2ae326517c27c559ace18b0f05b (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -
commit 54ea150f364f9c39a9f0a2abe5a98e82df62845a
Author: Matthias Dieter Wallnöfer mwallnoe...@yahoo.de
Date:   Thu Oct 1 13:59:02 2009 +0200

s4:ldb_msg_diff - Fixes up possible memory leaks and the python binding of 
it

---

Summary of changes:
 source4/lib/ldb/common/ldb_msg.c |   12 +---
 source4/lib/ldb/pyldb.c  |4 
 2 files changed, 13 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 702978a..929f24c 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;imsg1-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 0fe4da9..0dac61b 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);
 


-- 
Samba Shared Repository


Re: [SCM] Samba Shared Repository - branch master updated - tevent-0-9-8-833-g54ea150

2009-10-01 Thread Jelmer Vernooij
Hi Matthias,

On Thu, Oct 01, 2009 at 07:00:46AM -0500, Matthias Dieter Wallnöfer wrote:
 diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
 index 0fe4da9..0dac61b 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;
 + }

Please don't use KeyError for anything other than a key somewhere not
being found (e.g. trying to access an entry in a dictionary that
doesn't exist). In this particular case RuntimeError should be more
appropriate.

Cheers,

Jelmer