This is an automated email from the ASF dual-hosted git repository.
laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 2a9250bb2 [Refactor] Fix a memory leak warning
2a9250bb2 is described below
commit 2a9250bb21c83d0522a5e1ac144e7ac15fcbed01
Author: xinghuayu007 <[email protected]>
AuthorDate: Mon Dec 11 14:08:14 2023 +0800
[Refactor] Fix a memory leak warning
The following is the warning messege:
src/kudu/consensus/quorum_util-test.cc:104:1: warning: Potential
leak of memory pointed to by 'attrs_pb._M_t._M_t._M_head_impl'
[clang-analyzer-cplusplus.NewDeleteLeaks]
src/kudu/consensus/quorum_util-test.cc:1822:3: note: Calling 'AddPeer'
AddPeer(&config, "A", V, '+', {{"REPLACE", true}});
src/kudu/consensus/quorum_util-test.cc:85:3: note: Taking true branch
if (overall_health) {
src/kudu/consensus/quorum_util-test.cc:90:7: note: Assuming the condition
is true
if (!attrs.empty()) {
src/kudu/consensus/quorum_util-test.cc:90:3: note: Taking true branch
if (!attrs.empty()) {
src/kudu/consensus/quorum_util-test.cc:91:42: note: Memory is allocated
unique_ptr<RaftPeerAttrsPB> attrs_pb(new RaftPeerAttrsPB);
src/kudu/consensus/quorum_util-test.cc:104:1: note: Potential leak of
memory pointed to by 'attrs_pb._M_t._M_t._M_head_impl'
Change-Id: Ib83a99bfa8587a834c74843e1c0dd1c8da203c21
Reviewed-on: http://gerrit.cloudera.org:8080/20784
Reviewed-by: Yingchun Lai <[email protected]>
Tested-by: Yingchun Lai <[email protected]>
---
src/kudu/consensus/quorum_util-test.cc | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/kudu/consensus/quorum_util-test.cc
b/src/kudu/consensus/quorum_util-test.cc
index 240b29a45..a23acfdce 100644
--- a/src/kudu/consensus/quorum_util-test.cc
+++ b/src/kudu/consensus/quorum_util-test.cc
@@ -83,12 +83,11 @@ static void AddPeer(RaftConfigPB* config,
peer->mutable_last_known_addr()->set_host(uuid + ".example.com");
peer->set_member_type(type);
if (overall_health) {
- unique_ptr<HealthReportPB> health_report(new HealthReportPB);
- SetOverallHealth(health_report.get(), *overall_health);
- peer->set_allocated_health_report(health_report.release());
+ auto* health_report = peer->mutable_health_report();
+ SetOverallHealth(health_report, *overall_health);
}
if (!attrs.empty()) {
- unique_ptr<RaftPeerAttrsPB> attrs_pb(new RaftPeerAttrsPB);
+ auto* attrs_pb = peer->mutable_attrs();
for (const auto& attr : attrs) {
if (attr.first == "PROMOTE") {
attrs_pb->set_promote(attr.second);
@@ -98,7 +97,6 @@ static void AddPeer(RaftConfigPB* config,
FAIL() << attr.first << ": unexpected attribute to set";
}
}
- peer->set_allocated_attrs(attrs_pb.release());
}
}