From 0f6b4b43711522f4770fb256f328b4b1a3893ffc Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 17 Aug 2018 10:11:03 +0200 Subject: [PATCH] pygpo: Fix a talloc_tos() leak in py_gpo_get_unix_path cache_path() implicitly puts its result on talloc_tos(). As in py_gpo_get_unix_path the talloc_stackframe() is only created after the cache_path() call, we leak the result of cache_path() on talloc_tos() (which might or might not exist). This converts the function to the pattern used elsewhere: Create the stackframe as the very first action and remove it as the very last action in the function. Signed-off-by: Volker Lendecke Reviewed-by: Andreas Schneider --- libgpo/pygpo.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libgpo/pygpo.c b/libgpo/pygpo.c index 60220a6bc2a..88486424917 100644 --- a/libgpo/pygpo.c +++ b/libgpo/pygpo.c @@ -81,6 +81,8 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args, struct GROUP_POLICY_OBJECT *gpo_ptr \ = (struct GROUP_POLICY_OBJECT *)pytalloc_get_ptr(self); + frame = talloc_stackframe(); + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s", discard_const_p(char *, kwlist), &cache_dir)) { @@ -99,12 +101,8 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args, } } - frame = talloc_stackframe(); - status = gpo_get_unix_path(frame, cache_dir, gpo_ptr, &unix_path); - TALLOC_FREE(frame); - if (!NT_STATUS_IS_OK(status)) { PyErr_SetString(PyExc_SystemError, "Failed to determine gpo unix path"); @@ -114,6 +112,7 @@ static PyObject *py_gpo_get_unix_path(PyObject *self, PyObject *args, ret = PyStr_FromString(unix_path); out: + TALLOC_FREE(frame); return ret; } -- 2.47.2