]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
create and use context for VPs. Helps with #3937
authorAlan T. DeKok <aland@freeradius.org>
Fri, 26 Feb 2021 16:25:40 +0000 (11:25 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 26 Feb 2021 16:26:44 +0000 (11:26 -0500)
src/include/detail.h
src/main/detail.c

index d7ca13335fb8c62ee7d7858f215f11c67f177c14..5b5539baa150cdf05568f187701b72812e003eaa 100644 (file)
@@ -42,6 +42,8 @@ typedef struct listen_detail_t {
        int             delay_time;
        char const      *filename;
        char const      *filename_work;
+
+       TALLOC_CTX      *ctx;
        VALUE_PAIR      *vps;
        int             work_fd;
 
index 3c0e95cc0464260dff4256df67dbf4b9293879ee..835d7564bca224f4591502e51be256b5e4c5cde0 100644 (file)
@@ -506,6 +506,9 @@ open_file:
                /* FALL-THROUGH */
 
        case STATE_HEADER:
+               rad_assert(data->ctx == NULL);
+               MEM(data->ctx = talloc_init("detail"));
+
        do_header:
                data->done_entry = false;
                data->timestamp_offset = 0;
@@ -539,6 +542,7 @@ open_file:
                        DEBUG("detail (%s): Unlinking %s", data->name, data->filename_work);
                        unlink(data->filename_work);
                        if (data->fp) fclose(data->fp);
+                       TALLOC_FREE(data->ctx);
                        data->fp = NULL;
                        data->work_fd = -1;
                        data->state = STATE_UNOPENED;
@@ -666,7 +670,7 @@ open_file:
                                data->timestamp = atoi(value);
                                data->timestamp_offset = data->last_offset;
 
-                               vp = fr_pair_afrom_num(data, PW_PACKET_ORIGINAL_TIMESTAMP, 0);
+                               vp = fr_pair_afrom_num(data->ctx, PW_PACKET_ORIGINAL_TIMESTAMP, 0);
                                if (vp) {
                                        vp->vp_date = (uint32_t) data->timestamp;
                                        vp->type = VT_DATA;
@@ -690,7 +694,7 @@ open_file:
                         *      attributes like radsqlrelay does?
                         */
                        vp = NULL;
-                       if ((fr_pair_list_afrom_str(data, buffer, &vp) > 0) &&
+                       if ((fr_pair_list_afrom_str(data->ctx, buffer, &vp) > 0) &&
                            (vp != NULL)) {
                                fr_cursor_merge(&cursor, vp);
                        } else {
@@ -775,6 +779,7 @@ open_file:
                }
 
                fr_pair_list_free(&data->vps);
+               TALLOC_FREE(data->ctx);
                data->state = STATE_HEADER;
                goto do_header;
        }
@@ -786,6 +791,7 @@ open_file:
        if (data->done_entry) {
                DEBUG2("detail (%s): Skipping record for timestamp %lu", data->name, data->timestamp);
                fr_pair_list_free(&data->vps);
+               TALLOC_FREE(data->ctx);
                data->state = STATE_HEADER;
                goto do_header;
        }