{
const char * const kwnames[] = { "dn", NULL };
struct ldb_message *ret;
+ TALLOC_CTX *mem_ctx;
PyObject *pydn = NULL;
PyLdbMessageObject *py_ret;
&pydn))
return NULL;
- ret = ldb_msg_new(NULL);
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ ret = ldb_msg_new(mem_ctx);
if (ret == NULL) {
+ talloc_free(mem_ctx);
PyErr_NoMemory();
return NULL;
}
if (pydn != NULL) {
struct ldb_dn *dn;
if (!PyObject_AsDn(NULL, pydn, NULL, &dn)) {
- talloc_free(ret);
+ talloc_free(mem_ctx);
return NULL;
}
ret->dn = talloc_reference(ret, dn);
py_ret = (PyLdbMessageObject *)type->tp_alloc(type, 0);
if (py_ret == NULL) {
PyErr_NoMemory();
- talloc_free(ret);
+ talloc_free(mem_ctx);
return NULL;
}
- py_ret->mem_ctx = talloc_new(NULL);
- py_ret->msg = talloc_steal(py_ret->mem_ctx, ret);
+ py_ret->mem_ctx = mem_ctx;
+ py_ret->msg = ret;
return (PyObject *)py_ret;
}
static int py_ldb_msg_set_dn(PyLdbMessageObject *self, PyObject *value, void *closure)
{
struct ldb_message *msg = PyLdbMessage_AsMessage(self);
+ if (!PyLdbDn_Check(value)) {
+ PyErr_SetNone(PyExc_TypeError);
+ return -1;
+ }
+
msg->dn = talloc_reference(msg, PyLdbDn_AsDn(value));
return 0;
}
def setUp(self):
self.ldb = ldb.Ldb(filename())
+ def test_set_dn_invalid(self):
+ x = ldb.Message()
+ def assign():
+ x.dn = "astring"
+ self.assertRaises(TypeError, assign)
+
def test_eq(self):
x = ldb.Dn(self.ldb, "dc=foo11,bar=bloe")
y = ldb.Dn(self.ldb, "dc=foo11,bar=bloe")