From b1100f3c856866885489b04d97aba47d90ad5bf9 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Mon, 8 Oct 2018 19:15:37 +0000 Subject: [PATCH] fix memory leak at report batching Signed-off-by: Wayne Zhang --- src/istio/mixerclient/attribute_compressor.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/istio/mixerclient/attribute_compressor.cc b/src/istio/mixerclient/attribute_compressor.cc index 1a49622204b..6cdeda2dda2 100644 --- a/src/istio/mixerclient/attribute_compressor.cc +++ b/src/istio/mixerclient/attribute_compressor.cc @@ -128,8 +128,7 @@ class BatchCompressorImpl : public BatchCompressor { public: BatchCompressorImpl(const GlobalDictionary& global_dict) : global_dict_(global_dict), dict_(global_dict) { - report_ = google::protobuf::Arena::CreateMessage< - ::istio::mixer::v1::ReportRequest>(&arena_); + AllocReportProtobuf(); } void Add(const Attributes& attributes) override { @@ -148,14 +147,20 @@ class BatchCompressorImpl : public BatchCompressor { void Clear() override { dict_.Clear(); - report_->Clear(); + AllocReportProtobuf(); } private: + void AllocReportProtobuf() { + arena_.reset(new google::protobuf::Arena); + report_ = google::protobuf::Arena::CreateMessage< + ::istio::mixer::v1::ReportRequest>(arena_.get()); + } + const GlobalDictionary& global_dict_; - // protobuf arena - google::protobuf::Arena arena_; MessageDictionary dict_; + // protobuf arena + std::unique_ptr arena_; ::istio::mixer::v1::ReportRequest* report_; };