aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-02-13 11:50:10 +0100
committerMauro Sardara <msardara@cisco.com>2019-02-13 13:39:06 +0000
commit13fccc2bb1c2317061e6bf985c87bca647fb3b6f (patch)
tree77c33cc7542081b5cace6be16d4cddf118f9049c
parentcf3c377193654f2d8eda8a42d51a9c9363e9bd9e (diff)
[HICN-59] Do not call clear on membuf sharing same underlying memory. Use trimEnd instead.
Change-Id: I69463ede2b32f1d625b6161fabd08daca41c3483 Signed-off-by: Mauro Sardara <msardara@cisco.com>
-rw-r--r--libtransport/src/hicn/transport/core/connector.h3
-rw-r--r--libtransport/src/hicn/transport/utils/membuf.h3
2 files changed, 5 insertions, 1 deletions
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;