Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 6ee0885

Browse files
committed
Fix crashes on destruction with Botan 1.x
This horrible initializer must be deinit in the end (after all other Botan classes).
1 parent 5129e2b commit 6ee0885

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/controller.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include <QHostInfo>
2525
#include <QTcpSocket>
2626

27+
#ifndef USE_BOTAN2
2728
#include <botan/init.h>
29+
#endif
2830

2931
#include "controller.h"
3032
#include "encryptor.h"
@@ -44,7 +46,7 @@ Controller::Controller(Profile _profile,
4446
{
4547
#ifndef USE_BOTAN2
4648
try {
47-
Botan::LibraryInitializer::initialize("thread_safe");
49+
botanInit = std::make_unique<Botan::LibraryInitializer>("thread_safe");
4850
} catch (std::exception &e) {
4951
qFatal("Failed to initialise Botan library: %s", e.what());
5052
}
@@ -99,9 +101,6 @@ Controller::~Controller()
99101
if (tcpServer->isListening()) {
100102
stop();
101103
}
102-
#ifndef USE_BOTAN2
103-
Botan::LibraryInitializer::deinitialize();
104-
#endif
105104
}
106105

107106
bool Controller::start()

lib/controller.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
#include "profile.h"
3232
#include "udprelay.h"
3333

34+
#ifndef USE_BOTAN2
35+
namespace Botan {
36+
class LibraryInitializer;
37+
}
38+
#endif
39+
3440
namespace QSS {
3541

3642
class QSS_EXPORT Controller : public QObject
@@ -71,6 +77,12 @@ public slots:
7177
bool start(); // Return true if start successfully, otherwise return false
7278
void stop();
7379

80+
private:
81+
#ifndef USE_BOTAN2
82+
// This needs to be destructed in the end
83+
std::unique_ptr<Botan::LibraryInitializer> botanInit;
84+
#endif
85+
7486
protected:
7587
// The total bytes recevied or sent by/from all TCP and UDP connections.
7688
uint64_t bytesReceived;

0 commit comments

Comments
 (0)