From 165a2e92234f9326ae9f773a657681e4c4397a0e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Fri, 17 Jul 2026 10:24:33 +0200 Subject: [PATCH] src: avoid redundant DataPointer reallocations Signed-off-by: Filip Skokan --- deps/ncrypto/ncrypto.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc index 771589ed69b421..6d1e1305b4aa66 100644 --- a/deps/ncrypto/ncrypto.cc +++ b/deps/ncrypto/ncrypto.cc @@ -483,9 +483,12 @@ Buffer DataPointer::release() { } DataPointer DataPointer::resize(size_t len) { - size_t actual_len = std::min(len_, len); + const size_t actual_len = std::min(len_, len); + if (actual_len == len_) return std::move(*this); + auto buf = release(); - if (actual_len == len_) return DataPointer(buf.data, actual_len); + if (actual_len == 0) return DataPointer(buf.data, actual_len); + buf.data = OPENSSL_realloc(buf.data, actual_len); buf.len = actual_len; return DataPointer(buf);