From 18f879b857c174371a9fe27722c70051ed68ed64 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Sun, 9 Nov 2014 04:31:36 +0100 Subject: [PATCH] lib-pyldb: Avoid leaking memory in error cases Signed-off-by: Kamen Mazdrashki Reviewed-by: Andrew Bartlett --- lib/ldb/pyldb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index c541b7249e0..efac7b1be65 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -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; -- 2.34.1