From ff502f306c725de368dcc1d7db6ee90b4bd6ee1e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 24 Nov 2021 05:20:27 +0100 Subject: [PATCH] Initialize client lazily This prevents a use after free in the coeurl logging, if we exit immediately. --- src/MatrixClient.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/MatrixClient.cpp b/src/MatrixClient.cpp index 2ceb53a8..ea3799b6 100644 --- a/src/MatrixClient.cpp +++ b/src/MatrixClient.cpp @@ -28,22 +28,20 @@ Q_DECLARE_METATYPE(std::vector) Q_DECLARE_METATYPE(std::vector) Q_DECLARE_METATYPE(std::set) -namespace { -auto client_ = std::make_shared(); -} namespace http { mtx::http::Client * client() { + static auto client_ = std::make_shared(); return client_.get(); } bool is_logged_in() { - return !client_->access_token().empty(); + return !client()->access_token().empty(); } void