From ff502f306c725de368dcc1d7db6ee90b4bd6ee1e Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
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 2ceb53a8e..ea3799b6c 100644
--- a/src/MatrixClient.cpp
+++ b/src/MatrixClient.cpp
@@ -28,22 +28,20 @@ Q_DECLARE_METATYPE(std::vector<std::string>)
 Q_DECLARE_METATYPE(std::vector<QString>)
 Q_DECLARE_METATYPE(std::set<QString>)
 
-namespace {
-auto client_ = std::make_shared<mtx::http::Client>();
-}
 
 namespace http {
 
 mtx::http::Client *
 client()
 {
+    static auto client_ = std::make_shared<mtx::http::Client>();
     return client_.get();
 }
 
 bool
 is_logged_in()
 {
-    return !client_->access_token().empty();
+    return !client()->access_token().empty();
 }
 
 void
-- 
GitLab