From: Steve O'Brien Date: Wed, 30 Sep 2015 21:06:22 +0000 (-0700) Subject: folly Symbolizer: fix destruction-order fiasco problem X-Git-Tag: deprecate-dynamic-initializer~367 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f04e4550e868b4b6aaae011caefc05347520b676;p=folly.git folly Symbolizer: fix destruction-order fiasco problem Summary: On a (broken) unit test there is a bad `CHECK` during destruction time. This triggers an ABRT, goes through the signal handler, and in the process ends up doing a use-after-free. Moved some globals inside the functions in which they are used (w/ little duplication, as they are used in one place, mostly). Reviewed By: @luciang, @meyering Differential Revision: D2494046 --- diff --git a/folly/experimental/symbolizer/Symbolizer.cpp b/folly/experimental/symbolizer/Symbolizer.cpp index 28001216..f7e8e602 100644 --- a/folly/experimental/symbolizer/Symbolizer.cpp +++ b/folly/experimental/symbolizer/Symbolizer.cpp @@ -259,10 +259,10 @@ void Symbolizer::symbolize(const uintptr_t* addresses, } namespace { -const char kHexChars[] = "0123456789abcdef"; -const SymbolizePrinter::Color kAddressColor = SymbolizePrinter::Color::BLUE; -const SymbolizePrinter::Color kFunctionColor = SymbolizePrinter::Color::PURPLE; -const SymbolizePrinter::Color kFileColor = SymbolizePrinter::Color::DEFAULT; +constexpr char kHexChars[] = "0123456789abcdef"; +constexpr auto kAddressColor = SymbolizePrinter::Color::BLUE; +constexpr auto kFunctionColor = SymbolizePrinter::Color::PURPLE; +constexpr auto kFileColor = SymbolizePrinter::Color::DEFAULT; } // namespace constexpr char AddressFormatter::bufTemplate[]; @@ -347,22 +347,18 @@ void SymbolizePrinter::print(uintptr_t address, const SymbolizedFrame& frame) { } } -namespace { - -const std::map kColorMap = { - { SymbolizePrinter::Color::DEFAULT, "\x1B[0m" }, - { SymbolizePrinter::Color::RED, "\x1B[31m" }, - { SymbolizePrinter::Color::GREEN, "\x1B[32m" }, - { SymbolizePrinter::Color::YELLOW, "\x1B[33m" }, - { SymbolizePrinter::Color::BLUE, "\x1B[34m" }, - { SymbolizePrinter::Color::CYAN, "\x1B[36m" }, - { SymbolizePrinter::Color::WHITE, "\x1B[37m" }, - { SymbolizePrinter::Color::PURPLE, "\x1B[35m" }, -}; - -} - void SymbolizePrinter::color(SymbolizePrinter::Color color) { + static const std::map kColorMap = { + { SymbolizePrinter::Color::DEFAULT, "\x1B[0m" }, + { SymbolizePrinter::Color::RED, "\x1B[31m" }, + { SymbolizePrinter::Color::GREEN, "\x1B[32m" }, + { SymbolizePrinter::Color::YELLOW, "\x1B[33m" }, + { SymbolizePrinter::Color::BLUE, "\x1B[34m" }, + { SymbolizePrinter::Color::CYAN, "\x1B[36m" }, + { SymbolizePrinter::Color::WHITE, "\x1B[37m" }, + { SymbolizePrinter::Color::PURPLE, "\x1B[35m" }, + }; + if ((options_ & COLOR) == 0 && ((options_ & COLOR_IF_TTY) == 0 || !isTty_)) { return;