From 0a061fbb73922dee737bc50837ca7a3fc7b3001c Mon Sep 17 00:00:00 2001 From: Guillaume SMAHA Date: Thu, 9 Dec 2021 20:21:28 +0100 Subject: [PATCH] out_es: fix buffer size when converted_size is equal to 0. (#4414) In some case, ES_BULK_CHUNK is not enough to increase size of the buffer Fix #4412 Signed-off-by: Guillaume Smaha --- plugins/out_es/es_bulk.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/out_es/es_bulk.c b/plugins/out_es/es_bulk.c index 95f4e5cd8ac..20bbf9ff60e 100644 --- a/plugins/out_es/es_bulk.c +++ b/plugins/out_es/es_bulk.c @@ -81,14 +81,14 @@ int es_bulk_append(struct es_bulk *bulk, char *index, int i_len, if (converted_size == 0) { /* converted_size = 0 causes div/0 */ flb_debug("[out_es] converted_size is 0"); - append_size = ES_BULK_CHUNK; + append_size = required - available; } else { append_size = (whole_size - converted_size) /* rest of size to convert */ * (bulk->size / converted_size); /* = json size / msgpack size */ - if (append_size < ES_BULK_CHUNK) { - /* append at least ES_BULK_CHUNK size */ - append_size = ES_BULK_CHUNK; - } + } + if (append_size < ES_BULK_CHUNK) { + /* append at least ES_BULK_CHUNK size */ + append_size = ES_BULK_CHUNK; } ptr = flb_realloc(bulk->ptr, bulk->size + append_size); if (!ptr) {