diff --git a/src/Daemon/BaseDaemon.cpp b/src/Daemon/BaseDaemon.cpp index 1bdf811b5889..fdffca9b4ef8 100644 --- a/src/Daemon/BaseDaemon.cpp +++ b/src/Daemon/BaseDaemon.cpp @@ -706,6 +706,8 @@ BaseDaemon::~BaseDaemon() } signal_pipe.close(); + + SentryWriter::resetInstance(); } diff --git a/src/Daemon/SentryWriter.cpp b/src/Daemon/SentryWriter.cpp index f0f29053088c..9479dd65730c 100644 --- a/src/Daemon/SentryWriter.cpp +++ b/src/Daemon/SentryWriter.cpp @@ -72,6 +72,10 @@ SentryWriter * SentryWriter::getInstance() { return SentryWriter::instance.get(); } +void SentryWriter::resetInstance() +{ + SentryWriter::instance.reset(); +} SentryWriter::SentryWriter(Poco::Util::LayeredConfiguration & config) { @@ -254,6 +258,7 @@ void SentryWriter::sendError(Type type, int sig_or_error, const std::string & er void SentryWriter::initializeInstance(Poco::Util::LayeredConfiguration &) {} SentryWriter * SentryWriter::getInstance() { return nullptr; } +void SentryWriter::resetInstance() {} SentryWriter::SentryWriter(Poco::Util::LayeredConfiguration &) {} SentryWriter::~SentryWriter() = default; diff --git a/src/Daemon/SentryWriter.h b/src/Daemon/SentryWriter.h index ad23c3e5e550..231c8f700475 100644 --- a/src/Daemon/SentryWriter.h +++ b/src/Daemon/SentryWriter.h @@ -22,9 +22,16 @@ class SentryWriter /// Initialize static SentryWriter instance static void initializeInstance(Poco::Util::LayeredConfiguration & config); + /// @return nullptr if initializeInstance() was not called (i.e. for non-server) or SentryWriter object static SentryWriter * getInstance(); + /// SentryWriter static instance should be reset explicitly to avoid + /// possible use-after-free, since it may use some global objects (i.e. + /// OpenSSL), while sending final statistics + /// (SENTRY_SESSION_STATUS_EXITED). + static void resetInstance(); + void onSignal( int sig, const std::string & error_message,