From fe8fcd6d2fded7c94bd3e8fc3e489e3d9ba060ab Mon Sep 17 00:00:00 2001 From: Takuya ASADA Date: Tue, 8 Nov 2022 22:55:34 +0900 Subject: [PATCH] fsqual: stop causing memory leak error on LeakSanitizer When we enable the sanitizer, we get following error while running iotune: ==86505==ERROR: LeakSanitizer: detected memory leaks Direct leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x5701b8 in aligned_alloc (/home/syuu/seastar.2/build/sanitize/apps/iotune/iotune+0x5701b8) (BuildId: 411f9852d64ed8982d5b33d02489b5932d92b8b7) #1 0x6d0813 in seastar::filesystem_has_good_aio_support(seastar::basic_sstring, bool) /home/syuu/seastar.2/src/core/fsqual.cc:74:16 #2 0x5bcd0d in main::$_0::operator()() const::'lambda'()::operator()() const /home/syuu/seastar.2/apps/iotune/iotune.cc:742:21 #3 0x5bb1f1 in seastar::future seastar::futurize::apply(main::$_0::operator()() const::'lambda'()&&, std::tuple<>&&) /home/syuu/seastar.2/include/seastar/core/future.hh:2118:28 #4 0x5bb039 in seastar::futurize::type>::type seastar::async(seastar::thread_attributes, main::$_0::operator()() const::'lambda'()&&)::'lambda'()::operator()() const /home/syuu/seastar.2/include/seastar/core/thread.hh:258:13 #5 0x5bb039 in seastar::noncopyable_function::direct_vtable_for::type>::type seastar::async(seastar::thread_attributes, main::$_0::operator()() const::'lambda'()&&)::'lambda'()>::call(seastar::noncopyable_function const*) /home/syuu/seastar.2/include/seastar/util/noncopyable_function.hh:124:20 #6 0x8e0a77 in seastar::thread_context::main() /home/syuu/seastar.2/src/core/thread.cc:299:9 #7 0x7f30ff8547bf (/lib64/libc.so.6+0x547bf) (BuildId: 85c438f4ff93e21675ff174371c9c583dca00b2c) SUMMARY: AddressSanitizer: 4096 byte(s) leaked in 1 allocation(s). This is because we don't free buffer which allocated at filesystem_has_good_aio_support(), we should free it to avoid such error. And this is needed to test Scylla machine image with debug mode binary, since it tries to run iotune with the sanitizer and fails. Closes #1284 --- src/core/fsqual.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/fsqual.cc b/src/core/fsqual.cc index f816a1acab0..72f78fdae54 100644 --- a/src/core/fsqual.cc +++ b/src/core/fsqual.cc @@ -72,6 +72,7 @@ bool filesystem_has_good_aio_support(sstring directory, bool verbose) { auto bufsize = 4096; auto ctxsw = 0; auto buf = aligned_alloc(4096, 4096); + auto del = defer([&] () noexcept { ::free(buf); }); for (int i = 0; i < nr; ++i) { struct iocb cmd; cmd = make_write_iocb(fd.get(), bufsize*i, buf, bufsize);