diff options
author | George Hazan <george.hazan@gmail.com> | 2015-01-25 19:54:43 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-01-25 19:54:43 +0000 |
commit | 58ac4567a402d383c3edb0749b9f2fb88b8422d6 (patch) | |
tree | 224f909ab2abea950795d88b15b8b8a9e486551b /protocols/WhatsApp/src/connection.cpp | |
parent | dac1f42ef81ac1119430fd294a6b35b0b8cd6837 (diff) |
less pointers, less memory problems
git-svn-id: http://svn.miranda-ng.org/main/trunk@11906 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/connection.cpp')
-rw-r--r-- | protocols/WhatsApp/src/connection.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp index b970db7d96..ee4609fc75 100644 --- a/protocols/WhatsApp/src/connection.cpp +++ b/protocols/WhatsApp/src/connection.cpp @@ -77,7 +77,6 @@ void WhatsAppProto::stayConnectedLoop(void*) // -----------------------------
Mutex writerMutex;
- WALogin* login = NULL;
int desiredStatus;
bool error = false;
@@ -85,10 +84,6 @@ void WhatsAppProto::stayConnectedLoop(void*) while (true) {
if (connection != NULL) {
- if (connection->getLogin() == NULL && login != NULL) {
- delete login;
- login = NULL;
- }
delete connection;
connection = NULL;
}
@@ -123,20 +118,19 @@ void WhatsAppProto::stayConnectedLoop(void*) portNumber = 5222, resource += "-5222";
this->conn = new WASocketConnection("c.whatsapp.net", portNumber);
-
- connection = new WAConnection(&this->connMutex, this, this);
- login = new WALogin(connection, new BinTreeNodeReader(connection, conn, WAConnection::dictionary, WAConnection::DICTIONARY_LEN),
- new BinTreeNodeWriter(connection, conn, WAConnection::dictionary, WAConnection::DICTIONARY_LEN, &writerMutex),
- "s.whatsapp.net", this->phoneNumber, resource, password, nick);
-
- std::vector<unsigned char>* nextChallenge = login->login(*this->challenge);
- delete this->challenge;
- this->challenge = nextChallenge;
- connection->setLogin(login);
+ this->connection = new WAConnection(&this->connMutex, this, this);
+ {
+ WALogin login(connection, new BinTreeNodeReader(connection, conn), new BinTreeNodeWriter(connection, conn, &writerMutex), password);
+
+ std::vector<unsigned char>* nextChallenge = login.login(*this->challenge);
+ delete this->challenge;
+ this->challenge = nextChallenge;
+ connection->setLogin(&login);
+ }
+ connection->nick = this->nick;
connection->setVerboseId(true); // ?
- if (desiredStatus != ID_STATUS_INVISIBLE) {
+ if (desiredStatus != ID_STATUS_INVISIBLE)
connection->sendAvailableForChat();
- }
debugLogA("Set status to online");
this->m_iStatus = desiredStatus;
|