Skip to content

Commit

Permalink
fix: eliminated address sanitizer failures
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Oct 5, 2023
1 parent 7ba2f7b commit 15422f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/googletest.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <cstdlib>
#include <ctime>
#include <map>
#include <new>
#include <sstream>
#include <string>
#include <utility>
Expand Down Expand Up @@ -637,13 +638,21 @@ void (*g_new_hook)() = nullptr;

_END_GOOGLE_NAMESPACE_

void* operator new(size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
void* operator new(size_t size, const std::nothrow_t&) noexcept {
if (GOOGLE_NAMESPACE::g_new_hook) {
GOOGLE_NAMESPACE::g_new_hook();
}
return malloc(size);
}

void* operator new(size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
void* p = ::operator new(size, std::nothrow);
if (p == nullptr) {
throw std::bad_alloc{};
}
return p;
}

void* operator new[](size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
return ::operator new(size);
}
Expand Down
4 changes: 3 additions & 1 deletion src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,9 @@ static bool SendEmailInternal(const char*dest, const char *subject,
}
sanitized_dests << s;
}
dest = sanitized_dests.str().c_str();
// Avoid dangling reference
const std::string& tmp = sanitized_dests.str();
dest = tmp.c_str();

if ( use_logging ) {
VLOG(1) << "Trying to send TITLE:" << subject
Expand Down

0 comments on commit 15422f5

Please sign in to comment.