From eff908c2a43124b0c13a88d8f94abbf6d34a57e0 Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 26 Aug 2024 13:57:34 +0000 Subject: [PATCH] Replace recallocarray() with a realloc() + memset() combo. recallocarray(), with its guarantee that memory becoming unallocated is explicitly discarded, is too slow. In rpki-client forming one particular ibuf takes more then 4mins because every recallocarray() call ends up doing a fresh malloc + memcpy + freezero call. For sensitive data use ibuf_open() instead of ibuf_dynamic() to avoid any memory reallocations. OK tb@ --- lib/libutil/imsg-buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/libutil/imsg-buffer.c b/lib/libutil/imsg-buffer.c index 0708f486ee1..d45802d8d04 100644 --- a/lib/libutil/imsg-buffer.c +++ b/lib/libutil/imsg-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg-buffer.c,v 1.18 2023/12/12 15:47:41 claudio Exp $ */ +/* $OpenBSD: imsg-buffer.c,v 1.19 2024/08/26 13:57:34 claudio Exp $ */ /* * Copyright (c) 2023 Claudio Jeker @@ -94,9 +94,10 @@ ibuf_realloc(struct ibuf *buf, size_t len) return (-1); } - b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1); + b = realloc(buf->buf, buf->wpos + len); if (b == NULL) return (-1); + memset(b + buf->size, 0, buf->wpos + len - buf->size); buf->buf = b; buf->size = buf->wpos + len; -- 2.20.1