Skip to content

Commit 94d03f0

Browse files
authored
Make BackwardsTrace::addrMapping a string_view type (#40331)
Commit Message: Make BackwardsTrace::addrMapping a string_view type Additional Description: This makes it so in the event of it being triggered in a tsan context without having been initialized, it still doesn't malloc anything - it is a tsan error to malloc during a signal. Risk Level: Only crash-related so pretty safe. --------- Signed-off-by: Raven Black <[email protected]>
1 parent 30c7579 commit 94d03f0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

source/server/backtrace.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace Envoy {
88

99
bool BackwardsTrace::log_to_stderr_ = false;
1010

11-
const std::string& BackwardsTrace::addrMapping(bool setup) {
12-
CONSTRUCT_ON_FIRST_USE(std::string, [setup]() -> std::string {
11+
absl::string_view BackwardsTrace::addrMapping(bool setup) {
12+
static absl::string_view value = [setup]() -> absl::string_view {
1313
if (!setup) {
1414
return "";
1515
}
@@ -23,12 +23,14 @@ const std::string& BackwardsTrace::addrMapping(bool setup) {
2323
while (std::getline(maps, line)) {
2424
std::vector<absl::string_view> parts = absl::StrSplit(line, ' ');
2525
if (parts[1] == "r-xp") {
26-
return absl::StrCat(parts[0], " ", parts.back());
26+
static std::string result = absl::StrCat(parts[0], " ", parts.back());
27+
return result;
2728
}
2829
}
2930
#endif
3031
return "";
31-
}());
32+
}();
33+
return value;
3234
}
3335

3436
void BackwardsTrace::setLogToStderr(bool log_to_stderr) { log_to_stderr_ = log_to_stderr; }

source/server/backtrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BackwardsTrace : Logger::Loggable<Logger::Id::backtrace> {
5858
* e.g.
5959
* `7d34c0e28000-7d34c1e0d000 /build/foo/bar/source/exe/envoy-static`
6060
*/
61-
static const std::string& addrMapping(bool setup = false);
61+
static absl::string_view addrMapping(bool setup = false);
6262

6363
/**
6464
* Directs the output of logTrace() to directly stderr rather than the

0 commit comments

Comments
 (0)