summaryrefslogtreecommitdiffstats
path: root/src/crush/CrushWrapper.h
diff options
context:
space:
mode:
authorRongqi Sun <sunrongqi@huawei.com>2024-05-08 10:16:13 +0200
committerRongqi Sun <sunrongqi@huawei.com>2024-05-09 11:33:54 +0200
commit7bae43964c598410aa918316b46d22985d78c42b (patch)
tree894c3b303d00f71d641987629d6217af555aad1b /src/crush/CrushWrapper.h
parentMerge pull request #56390 from rhcs-dashboard/rgw-add-system-user (diff)
downloadceph-7bae43964c598410aa918316b46d22985d78c42b.tar.xz
ceph-7bae43964c598410aa918316b46d22985d78c42b.zip
crush/builder: free 'crush_rule' before return
When sanitizer is enabled, unittest_erasure_code_shec shows: ``` ================================================================= ==437976==ERROR: LeakSanitizer: detected memory leaks Direct leak of 2021708 byte(s) in 29731 object(s) allocated from: #0 0xaaaab0144820 in malloc (/root/ceph-19.0.0/build/bin/unittest_erasure_code_shec+0x1d4820) (BuildId: c0999ecf82504ed7e184ea4b4b9ae9d32faa1c46) #1 0xffffa770057c in crush_make_rule /root/ceph-19.0.0/src/crush/builder.c:104:9 #2 0xffffa7751638 in CrushWrapper::add_simple_rule_at(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, std::ostream*) /root/ceph-19.0.0/src/crush/CrushWrapper.cc:2327:22 #3 0xffffa7751d2c in CrushWrapper::add_simple_rule(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::ostream*) /root/ceph-19.0.0/src/crush/CrushWrapper.cc:2369:10 #4 0xffffa39d6198 in ceph::ErasureCode::create_rule(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CrushWrapper&, std::ostream*) const /root/ceph-19.0.0/src/erasure-code/ErasureCode.cc:76:18 #5 0xaaaab01f5a6c in thread3(void*) /root/ceph-19.0.0/src/test/erasure-code/TestErasureCodeShec.cc:2756:11 #6 0xffffa2dad5c4 in start_thread nptl/./nptl/pthread_create.c:442:8 #7 0xffffa2e15ed8 misc/../sysdeps/unix/sysv/linux/aarch64/clone.S:79 SUMMARY: AddressSanitizer: 2021708 byte(s) leaked in 29731 allocation(s). ``` When crush_add_rule exceeds the number of max_rules, crush_rule shoule be freed right before returning in caller site. Signed-off-by: Rongqi Sun <sunrongqi@huawei.com>
Diffstat (limited to 'src/crush/CrushWrapper.h')
-rw-r--r--src/crush/CrushWrapper.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h
index 7018ca498c6..89de2024d35 100644
--- a/src/crush/CrushWrapper.h
+++ b/src/crush/CrushWrapper.h
@@ -1172,6 +1172,9 @@ public:
crush_rule *n = crush_make_rule(len, type);
ceph_assert(n);
ruleno = crush_add_rule(crush, n, ruleno);
+ if (ruleno < 0) {
+ free(n);
+ }
return ruleno;
}
int set_rule_step(unsigned ruleno, unsigned step, int op, int arg1, int arg2) {