From 2e3e1bf777c475dac9d1794826d28eb848b613c4 Mon Sep 17 00:00:00 2001 From: APTX Date: Thu, 7 Jun 2012 03:04:29 +0200 Subject: [PATCH] Add automatic cleanup of Client instance --- client.cpp | 14 ++++++++++++++ client.h | 1 + 2 files changed, 15 insertions(+) diff --git a/client.cpp b/client.cpp index aecddc3..e8afc70 100644 --- a/client.cpp +++ b/client.cpp @@ -32,6 +32,8 @@ Client::Client(QObject *parent) : ClientInterface(parent) #ifdef ANIDBUDPCLIENT_CLIENT_MISC_DEBUG qDebug() << "Api instance init!"; #endif + init(); + authReply = 0; uptimeReply = 0; encryptReply = 0; @@ -848,6 +850,8 @@ Client *Client::instance() void Client::destroy() { + if (!m_instance) + return; delete m_instance; m_instance = 0; } @@ -1025,6 +1029,16 @@ bool Client::possiblyValid(const QByteArray &reply) const return false; } +void Client::init() +{ + static bool done = false; + if (done) + return; + done = true; + + qAddPostRoutine(Client::destroy); +} + void Client::commandTimeout() { Q_ASSERT(!sentCommandOrder.isEmpty()); diff --git a/client.h b/client.h index 7ff5348..5784f55 100644 --- a/client.h +++ b/client.h @@ -203,6 +203,7 @@ private: EncryptCommand encryptCommand; EncryptReply *encryptReply; + static void init(); static Client *m_instance; static const int UDP_DATAGRAM_MAXIMUM_SIZE = 1400; -- 2.52.0