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

Commit

Permalink
Fix crashes on destruction with Botan 1.x
Browse files Browse the repository at this point in the history
This horrible initializer must be deinit in the end (after all other
Botan classes).
  • Loading branch information
librehat committed Jan 4, 2018
1 parent 5129e2b commit 6ee0885
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <QHostInfo>
#include <QTcpSocket>

#ifndef USE_BOTAN2
#include <botan/init.h>
#endif

#include "controller.h"
#include "encryptor.h"
Expand All @@ -44,7 +46,7 @@ Controller::Controller(Profile _profile,
{
#ifndef USE_BOTAN2
try {
Botan::LibraryInitializer::initialize("thread_safe");
botanInit = std::make_unique<Botan::LibraryInitializer>("thread_safe");
} catch (std::exception &e) {
qFatal("Failed to initialise Botan library: %s", e.what());
}
Expand Down Expand Up @@ -99,9 +101,6 @@ Controller::~Controller()
if (tcpServer->isListening()) {
stop();
}
#ifndef USE_BOTAN2
Botan::LibraryInitializer::deinitialize();
#endif
}

bool Controller::start()
Expand Down
12 changes: 12 additions & 0 deletions lib/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include "profile.h"
#include "udprelay.h"

#ifndef USE_BOTAN2
namespace Botan {
class LibraryInitializer;
}
#endif

namespace QSS {

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

private:
#ifndef USE_BOTAN2
// This needs to be destructed in the end
std::unique_ptr<Botan::LibraryInitializer> botanInit;
#endif

protected:
// The total bytes recevied or sent by/from all TCP and UDP connections.
uint64_t bytesReceived;
Expand Down

0 comments on commit 6ee0885

Please sign in to comment.