From: NitzanMordhai Date: Thu, 25 Aug 2022 11:18:56 +0000 (+0000) Subject: common/ceph_context: leak some memory fail to show in valgrind X-Git-Tag: v17.2.6~462^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a8c617846a87b5f8fa05c70445467794f71f6d79;p=ceph.git common/ceph_context: leak some memory fail to show in valgrind GCC 20 memory optimization broke the memory leak for testing. Fixes:https://tracker.ceph.com/issues/57165 Signed-off-by: Nitzan Mordechai (cherry picked from commit fc21669d262117312b290c004390a70d92b9acea) --- diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index df23ae7a60f1..e52c626e57c6 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -502,6 +502,14 @@ int CephContext::do_command(std::string_view command, const cmdmap_t& cmdmap, } } +#pragma GCC push_options +#pragma GCC optimize ("O0") +static void leak_some_memory() { + volatile char *foo = new char[1234]; + (void)foo; +} +#pragma GCC pop_options + int CephContext::_do_command( std::string_view command, const cmdmap_t& cmdmap, Formatter *f, @@ -520,8 +528,7 @@ int CephContext::_do_command( } } if (command == "leak_some_memory") { - char *foo = new char[1234]; - (void)foo; + leak_some_memory(); } else if (command == "perfcounters_dump" || command == "1" || command == "perf dump") {