pygpo: Fix a talloc_tos() leak in py_gpo_get_unix_path
authorVolker Lendecke <vl@samba.org>
Fri, 17 Aug 2018 08:11:03 +0000 (10:11 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 17 Aug 2018 09:30:10 +0000 (11:30 +0200)
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 <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
libgpo/pygpo.c

index 60220a6bc2a76697b0ff1674530d6b2eb2d83c35..88486424917f307961c4a4086434457ed2a8e8ce 100644 (file)
@@ -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;
 }