8000 Bug fix/improve invalid parameter handler (#7077) · botnick/arangodb@4a32fcd · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a32fcd

Browse files
dothebartfceller
authored andcommitted
Bug fix/improve invalid parameter handler (arangodb#7077)
* don't use icu to convert utf16 here, it may already be de-initialized. * don't use atexit handler, so we can use _exit on windows * use _exit() here.
1 parent 83785de commit 4a32fcd

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

lib/Basics/files.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,14 +2012,23 @@ static std::unique_ptr<char[]> SystemTempPath;
20122012
/// @brief user-defined temp path
20132013
static std::string UserTempPath;
20142014

2015-
static void SystemTempPathCleaner(void) {
2016-
char* path = SystemTempPath.get();
2015+
class SystemTempPathSweeper {
2016+
std::string _systemTempPath;
2017+
public:
2018+
SystemTempPathSweeper() : _systemTempPath(){};
20172019

2018-
if (path != nullptr) {
2019-
// delete directory iff directory is empty
2020-
TRI_RMDIR(path);
2020+
~SystemTempPathSweeper(void) {
2021+
if (!_systemTempPath.empty()) {
2022+
// delete directory iff directory is empty
2023+
TRI_RMDIR(_systemTempPath.c_str());
2024+
}
20212025
}
2022-
}
2026+
void init(const char *path) {
2027+
_systemTempPath = path;
2028+
}
2029+
};
2030+
2031+
SystemTempPathSweeper SystemTempPathSweeperInstance;
20232032

20242033
// The TempPath is set but not created
20252034
void TRI_SetTempPath(std::string const& temp) {
@@ -2096,12 +2105,13 @@ std::string TRI_GetTempPath() {
20962105
std::this_thread::sleep_for(std::chrono::milliseconds(5 + RandomGenerator::interval(uint64_t(20))));
20972106
}
20982107

2099-
atexit(SystemTempPathCleaner);
2108+
SystemTempPathSweeperInstance.init(SystemTempPath.get());
21002109
}
21012110

21022111
return std::string(path);
21032112
}
21042113

2114+
21052115
////////////////////////////////////////////////////////////////////////////////
21062116
/// @brief get a temporary file name
21072117
////////////////////////////////////////////////////////////////////////////////

lib/Basics/win-utils.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,23 @@ static void InvalidParameterHandler(
9999
uintptr_t pReserved) { // in case microsoft forget something
100100

101101
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
102-
std::string exp;
103-
std::string func;
104-
std::string fileName;
105-
106-
UnicodeString uStr;
107-
uStr = expression;
108-
uStr.toUTF8String(exp);
109-
uStr = function;
110-
uStr.toUTF8String(func);
111-
uStr = file;
112-
uStr.toUTF8String(fileName);
113-
114-
std::string bt;
115-
TRI_GetBacktrace(bt);
102+
char buf[1024] = "";
103+
snprintf(buf, 1023,
104+
" Expression: %ls Function: %ls File: %ls Line: %ld",
105+
expression, function, file, line);
106+
buf[1024] = '\0';
116107
#endif
117108

118109
LOG_TOPIC(ERR, arangodb::Logger::FIXME) <<
119110
"Invalid handle parameter passed"
120111
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
121112
<<
122-
" Expression: " << exp <<
123-
" Function: " << func <<
124-
" File: " << fileName <<
125-
" Line: " << std::to_string(line) <<
126-
" Backtrace: " << bt
113+
buf;
114+
115+
std::string bt;
116+
TRI_GetBacktrace(bt);
117+
LOG_TOPIC(ERR, arangodb::Logger::FIXME) <<
118+
"Invalid handle parameter Invoked from: " << bt
127119
#endif
128120
;
129121
}
@@ -651,7 +643,7 @@ void ADB_WindowsExitFunction(int exitCode, void* data) {
651643
serviceAbort(exitCode);
652644
}
653645

654-
exit(exitCode);
646+
_exit(exitCode);
655647
}
656648

657649
// Detect cygwin ssh / terminals

0 commit comments

Comments
 (0)
0