From bf0b178c4d1a39885e204e26a08cd65c186f1c43 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 23 Sep 2024 14:27:22 -0400 Subject: [PATCH] MT#55283 upgrade minimum chunk allocation size Change-Id: I2fafa4055be06b22671abf789ea51cf6409c5e1b --- daemon/bencode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/daemon/bencode.c b/daemon/bencode.c index 68b0961c8e..d83e858e0b 100644 --- a/daemon/bencode.c +++ b/daemon/bencode.c @@ -11,7 +11,7 @@ #include "helpers.h" /* set to 0 for alloc debugging, e.g. through valgrind */ -#define BENCODE_MIN_BUFFER_PIECE_LEN 512 +#define BENCODE_MIN_BUFFER_PIECE_LEN 4096 #define BENCODE_HASH_BUCKETS 31 /* prime numbers work best */ @@ -78,14 +78,14 @@ static void __bencode_list_init(bencode_item_t *list) { static struct __bencode_buffer_piece *__bencode_piece_new(size_t size) { struct __bencode_buffer_piece *ret; - if (size < BENCODE_MIN_BUFFER_PIECE_LEN) - size = BENCODE_MIN_BUFFER_PIECE_LEN; - ret = BENCODE_MALLOC(sizeof(*ret) + size + BENCODE_ALLOC_ALIGN); + size_t alloc_size = size + sizeof(*ret) + BENCODE_ALLOC_ALIGN; + alloc_size = MAX(alloc_size, BENCODE_MIN_BUFFER_PIECE_LEN); + ret = BENCODE_MALLOC(alloc_size); if (!ret) return NULL; ret->tail = ret->buf; - ret->left = size; + ret->left = alloc_size - sizeof(*ret) - BENCODE_ALLOC_ALIGN; ret->next = NULL; return ret;