mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
lib/ldb: py LDBError avoids leak and checks for alloc failure
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
ffa08426e0
commit
1d8024e733
@ -266,13 +266,25 @@ static PyTypeObject PyLdbControl = {
|
||||
|
||||
static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
|
||||
{
|
||||
if (ret == LDB_ERR_PYTHON_EXCEPTION)
|
||||
PyObject *exc = NULL;
|
||||
if (ret == LDB_ERR_PYTHON_EXCEPTION) {
|
||||
return; /* Python exception should already be set, just keep that */
|
||||
|
||||
PyErr_SetObject(error,
|
||||
Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
|
||||
ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
|
||||
}
|
||||
exc = Py_BuildValue("(i,s)", ret,
|
||||
ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx));
|
||||
if (exc == NULL) {
|
||||
/*
|
||||
* Py_BuildValue failed, and will have set its own exception.
|
||||
* It isn't the one we wanted, but it will have to do.
|
||||
* This is all very unexpected.
|
||||
*/
|
||||
fprintf(stderr, "could not make LdbError %d!\n", ret);
|
||||
return;
|
||||
}
|
||||
PyErr_SetObject(error, exc);
|
||||
Py_DECREF(exc);
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_bytes_str(PyBytesObject *self)
|
||||
{
|
||||
char *msg = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user