From 13fccc2bb1c2317061e6bf985c87bca647fb3b6f Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Wed, 13 Feb 2019 11:50:10 +0100 Subject: [HICN-59] Do not call clear on membuf sharing same underlying memory. Use trimEnd instead. Change-Id: I69463ede2b32f1d625b6161fabd08daca41c3483 Signed-off-by: Mauro Sardara --- libtransport/src/hicn/transport/core/connector.h | 3 ++- libtransport/src/hicn/transport/utils/membuf.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'libtransport') diff --git a/libtransport/src/hicn/transport/core/connector.h b/libtransport/src/hicn/transport/core/connector.h index c5250486c..ae82ee973 100644 --- a/libtransport/src/hicn/transport/core/connector.h +++ b/libtransport/src/hicn/transport/core/connector.h @@ -76,7 +76,8 @@ class Connector { result.second->separateChain(result.second->next(), result.second->prev()); } - result.second->clear(); + + result.second->trimEnd(result.second->length()); return std::move(result.second); } diff --git a/libtransport/src/hicn/transport/utils/membuf.h b/libtransport/src/hicn/transport/utils/membuf.h index 5a10d4182..a150483b1 100644 --- a/libtransport/src/hicn/transport/utils/membuf.h +++ b/libtransport/src/hicn/transport/utils/membuf.h @@ -225,6 +225,9 @@ class MemBuf { void trimEnd(std::size_t amount) { length_ -= amount; } + // Never call clear on cloned membuf sharing different + // portions of the same underlying buffer. + // Use the trim functions instead. void clear() { data_ = writableBuffer(); length_ = 0; -- cgit 1.2.3-korg