lib-pyldb: Avoid leaking memory in error cases
authorKamen Mazdrashki <kamenim@samba.org>
Sun, 9 Nov 2014 03:31:36 +0000 (04:31 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 25 Nov 2014 04:04:07 +0000 (05:04 +0100)
Signed-off-by: Kamen Mazdrashki <kamenim@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index c541b7249e035a1eea90bf3e9a7ee01208cc4292..efac7b1be65652099dd57445c289dc21bb84d508 100644 (file)
@@ -1624,8 +1624,6 @@ static PyObject *py_ldb_schema_format_value(PyLdbObject *self, PyObject *args)
        if (!PyArg_ParseTuple(args, "sO", &element_name, &val))
                return NULL;
 
-       mem_ctx = talloc_new(NULL);
-
        old_val.data = (uint8_t *)PyString_AsString(val);
        old_val.length = PyString_Size(val);
 
@@ -1640,6 +1638,12 @@ static PyObject *py_ldb_schema_format_value(PyLdbObject *self, PyObject *args)
                Py_RETURN_NONE;
        }
 
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
        if (a->syntax->ldif_write_fn(pyldb_Ldb_AsLdbContext(self), mem_ctx, &old_val, &new_val) != 0) {
                talloc_free(mem_ctx);
                Py_RETURN_NONE;