From: Douglas Bagnall Date: Wed, 21 Feb 2024 22:19:30 +0000 (+1300) Subject: pyldb: add a macro to free when raising exceptions X-Git-Tag: tdb-1.4.11~1656 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cccc994fa076f3f784bce7258a95d756d44cd190;p=thirdparty%2Fsamba.git pyldb: add a macro to free when raising exceptions We often forget. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/pyldb.h b/lib/ldb/pyldb.h index 2d354422cdb..45637b76691 100644 --- a/lib/ldb/pyldb.h +++ b/lib/ldb/pyldb.h @@ -110,7 +110,15 @@ typedef struct { } \ } while(0) -/* Picked out of thin air. To do this properly, we should probably have some part of the +#define PyErr_LDB_ERROR_IS_ERR_RAISE_FREE(err,ret,ldb,mem_ctx) do { \ + if (ret != LDB_SUCCESS) { \ + PyErr_SetLdbError(err, ret, ldb); \ + TALLOC_FREE(mem_ctx); \ + return NULL; \ + } \ +} while(0) + +/* Picked out of thin air. To do this properly, we should probably have some part of the * errors in LDB be allocated to bindings ? */ #define LDB_ERR_PYTHON_EXCEPTION 142