]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use condition as talloc_ctx
authorAlan T. DeKok <aland@freeradius.org>
Thu, 5 Sep 2019 23:13:50 +0000 (19:13 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 5 Sep 2019 23:13:50 +0000 (19:13 -0400)
to avoid leaking memory.  It's leaked only in the tests,
but whatever.

src/lib/server/cond_tokenize.c

index 715483ca93f0d3e11befbbf56eab0452855600d2..22d196e8930ee49a4009134f61b6c5daf46fd87f 100644 (file)
@@ -572,7 +572,7 @@ static ssize_t cond_check_attrs(fr_cond_t *c, char const *start,
 /*
  *     Like tmpl_preparse(), but expands variables.
  */
-static ssize_t cond_preparse(char const **out, size_t *outlen, char const *start,
+static ssize_t cond_preparse(TALLOC_CTX *ctx, char const **out, size_t *outlen, char const *start,
                             FR_TOKEN *type, char const **error,
                             fr_dict_attr_t const **castda, bool require_regex,
                             CONF_SECTION *parent, char const *filename, int lineno)
@@ -596,7 +596,7 @@ static ssize_t cond_preparse(char const **out, size_t *outlen, char const *start
        /*
         *      cf_expand_variables() doesn't take a length.  Oh well...
         */
-       expanded = talloc_strndup(parent, start, slen);
+       expanded = talloc_strndup(ctx, start, slen);
        if (!expanded) {
        oom:
                *error = "Failed allocating memory";
@@ -623,7 +623,7 @@ static ssize_t cond_preparse(char const **out, size_t *outlen, char const *start
         *      'out' now points to 'buffer', which we don't want.  So
         *      we need to return a string which the caller can keep track of.
         */
-       expanded = talloc_strndup(parent, *out, *outlen);
+       expanded = talloc_strndup(ctx, *out, *outlen);
        if (!expanded) goto oom;
 
        *out = expanded;
@@ -727,7 +727,7 @@ static ssize_t cond_tokenize(TALLOC_CTX *ctx, fr_cond_t **pcond, char const **er
        /*
         *      Grab the LHS
         */
-       slen = cond_preparse(&lhs, &lhs_len, p, &lhs_type, error, &c->cast, false, parent, filename, lineno);
+       slen = cond_preparse(c, &lhs, &lhs_len, p, &lhs_type, error, &c->cast, false, parent, filename, lineno);
        if (slen <= 0) {
                return_SLEN;
        }
@@ -907,7 +907,7 @@ static ssize_t cond_tokenize(TALLOC_CTX *ctx, fr_cond_t **pcond, char const **er
                        return_P("Expected text after operator");
                }
 
-               slen = cond_preparse(&rhs, &rhs_len, p, &rhs_type, error, NULL, regex, parent, filename, lineno);
+               slen = cond_preparse(c, &rhs, &rhs_len, p, &rhs_type, error, NULL, regex, parent, filename, lineno);
                if (slen <= 0) {
                        return_SLEN;
                }