From acd5ce31c21b59e9d1522bb1b21ee683cc13586d Mon Sep 17 00:00:00 2001 From: Herwin Weststrate Date: Mon, 3 Apr 2023 18:35:30 +0200 Subject: [PATCH] Break in rest_request_encode_wrapper when at the end The old code still ran one more loop once the request has been finished. This not only included a new memory allocation + move + free, but it also resulted in the limit argument being effectively cut in half. --- src/modules/rlm_rest/rest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/rlm_rest/rest.c b/src/modules/rlm_rest/rest.c index 9db0c0fb1e..035f5578fe 100644 --- a/src/modules/rlm_rest/rest.c +++ b/src/modules/rlm_rest/rest.c @@ -964,6 +964,7 @@ static ssize_t rest_request_encode_wrapper(char **buffer, rest_read_t func, size size_t alloc = REST_BODY_INIT; /* Size of buffer to alloc */ size_t used = 0; /* Size of data written */ size_t len = 0; + rlm_rest_request_t *ctx = userdata; while (alloc <= limit) { current = rad_malloc(alloc); @@ -975,7 +976,7 @@ static ssize_t rest_request_encode_wrapper(char **buffer, rest_read_t func, size len = func(current + used, alloc - used, 1, userdata); used += len; - if (!len) { + if (ctx->state == READ_STATE_END || !len) { *buffer = current; return used; } -- 2.47.3