From 2c78ef48e32605fc88b67186ac558a6c67f46261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= Date: Mon, 7 Jun 2021 15:39:06 +0200 Subject: [PATCH] Change plain char buffer to unique_ptr to free memory at function exit. Visible in `rr record simple` with asan enabled rr build. ==647542==ERROR: LeakSanitizer: detected memory leaks Direct leak of 19 byte(s) in 1 object(s) allocated from: 0x7fe6e70187a7 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:102 0x55a421ec5ca1 in simple_to_lower /home/bernhard/data/entwicklung/2021/rr/2021-04-25/rr/src/log.cc:62 0x55a421ec6f3b in get_log_level /home/bernhard/data/entwicklung/2021/rr/2021-04-25/rr/src/log.cc:191 0x55a421ec7766 in get_log_module /home/bernhard/data/entwicklung/2021/rr/2021-04-25/rr/src/log.cc:224 ... --- src/log.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/log.cc b/src/log.cc index 93dcc996e78..67cc422a4c3 100644 --- a/src/log.cc +++ b/src/log.cc @@ -59,12 +59,12 @@ static char simple_to_lower(char ch) { } static string simple_to_lower(const string& s) { - char* buf = new char[s.size() + 1]; + std::unique_ptr buf(new char[s.size() + 1]); for (size_t i = 0; i < s.size(); ++i) { buf[i] = simple_to_lower(s[i]); } buf[s.size()] = 0; - return string(buf); + return string(buf.get()); } #if __has_attribute(require_constant_initialization)