Major updates integration from all upstreams
This commit is contained in:
19
src/util.cpp
19
src/util.cpp
@@ -20,6 +20,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
|
||||
#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
|
||||
#include <pthread.h>
|
||||
@@ -127,7 +128,7 @@ void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAF
|
||||
}
|
||||
|
||||
// Init
|
||||
class CInit
|
||||
static class CInit
|
||||
{
|
||||
public:
|
||||
CInit()
|
||||
@@ -182,6 +183,20 @@ static FILE* fileout = NULL;
|
||||
static boost::mutex* mutexDebugLog = NULL;
|
||||
static list<string> *vMsgsBeforeOpenLog;
|
||||
|
||||
[[noreturn]] void new_handler_terminate()
|
||||
{
|
||||
// Rather than throwing std::bad-alloc if allocation fails, terminate
|
||||
// immediately to (try to) avoid chain corruption.
|
||||
// Since LogPrintf may itself allocate memory, set the handler directly
|
||||
// to terminate first.
|
||||
std::set_new_handler(std::terminate);
|
||||
fputs("Error: Out of memory. Terminating.\n", stderr);
|
||||
LogPrintf("Error: Out of memory. Terminating.\n");
|
||||
|
||||
// The log was successful, terminate now.
|
||||
std::terminate();
|
||||
};
|
||||
|
||||
static int FileWriteStr(const std::string &str, FILE *fp)
|
||||
{
|
||||
return fwrite(str.data(), 1, str.size(), fp);
|
||||
@@ -226,7 +241,7 @@ bool LogAcceptCategory(const char* category)
|
||||
// This helps prevent issues debugging global destructors,
|
||||
// where mapMultiArgs might be deleted before another
|
||||
// global destructor calls LogPrint()
|
||||
static boost::thread_specific_ptr<set<string> > ptrCategory;
|
||||
static boost::thread_specific_ptr<set<string>> ptrCategory;
|
||||
if (ptrCategory.get() == NULL)
|
||||
{
|
||||
const vector<string>& categories = mapMultiArgs["-debug"];
|
||||
|
||||
Reference in New Issue
Block a user