fix: address sanitizer failures (#956)

This commit is contained in:
Sergiu Deitsch 2023-10-06 00:34:38 +02:00 committed by GitHub
parent 7ba2f7bc02
commit e567cfc442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -45,6 +45,7 @@
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <map> #include <map>
#include <new>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <utility> #include <utility>
@ -637,13 +638,21 @@ void (*g_new_hook)() = nullptr;
_END_GOOGLE_NAMESPACE_ _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) { if (GOOGLE_NAMESPACE::g_new_hook) {
GOOGLE_NAMESPACE::g_new_hook(); GOOGLE_NAMESPACE::g_new_hook();
} }
return malloc(size); 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 { void* operator new[](size_t size) GOOGLE_GLOG_THROW_BAD_ALLOC {
return ::operator new(size); return ::operator new(size);
} }

View File

@ -2268,7 +2268,9 @@ static bool SendEmailInternal(const char*dest, const char *subject,
} }
sanitized_dests << s; 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 ) { if ( use_logging ) {
VLOG(1) << "Trying to send TITLE:" << subject VLOG(1) << "Trying to send TITLE:" << subject