From 2fc07408689c9945b802d7d1532e2990ef57bea7 Mon Sep 17 00:00:00 2001 From: Yevgeniy Miretskiy Date: Sun, 17 Nov 2019 14:39:11 -0500 Subject: [PATCH] libroach: Fix memory leak in row_counter Free previous key memory when counting row keys. Release note (bug fix): Do not leak memory when counting rows during backup. --- c-deps/libroach/row_counter.cc | 6 ++++-- c-deps/libroach/row_counter.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/c-deps/libroach/row_counter.cc b/c-deps/libroach/row_counter.cc index b90aa4bc788e..3b564cce2d8a 100644 --- a/c-deps/libroach/row_counter.cc +++ b/c-deps/libroach/row_counter.cc @@ -88,10 +88,12 @@ bool RowCounter::Count(const rocksdb::Slice& key, cockroach::roachpb::BulkOpSumm } // no change key prefix => no new row. - if (decoded_key.data() == prev_key.data) { + if (decoded_key == prev_key) { return true; } - prev_key = ToDBString(decoded_key); + + + prev_key.assign(decoded_key.data(), decoded_key.size()); uint64_t tbl; if (!DecodeTablePrefix(&decoded_key, &tbl)) { diff --git a/c-deps/libroach/row_counter.h b/c-deps/libroach/row_counter.h index b9178d5529ab..804363dc1aa5 100644 --- a/c-deps/libroach/row_counter.h +++ b/c-deps/libroach/row_counter.h @@ -29,6 +29,6 @@ struct RowCounter { private: void EnsureSafeSplitKey(rocksdb::Slice* key); int GetRowPrefixLength(rocksdb::Slice* key); - DBString prev_key; + std::string prev_key; rocksdb::Slice prev; };