Skip to content

Commit

Permalink
Change plain char buffer to unique_ptr to free memory at function exit.
Browse files Browse the repository at this point in the history
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
...
  • Loading branch information
bernhardu authored and rocallahan committed Jun 7, 2021
1 parent 177a0d6 commit 2c78ef4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char[]> 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)
Expand Down

0 comments on commit 2c78ef4

Please sign in to comment.