From 510f938a5c6f0ee95ac0b36e56aced065228298e Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 10 Sep 2015 11:58:58 +0000 Subject: Tox: tox pointers should store in PollingThread to avoid cross thread using git-svn-id: http://svn.miranda-ng.org/main/trunk@15316 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_profile.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'protocols/Tox/src/tox_profile.cpp') diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index d6fff1c75d..82754c5d6c 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -59,7 +59,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) if (data && tox_is_data_encrypted(data)) { - password = mir_utf8encodeW(ptrT(getTStringA("Password"))); + pass_ptrA password(mir_utf8encodeW(pass_ptrT(getTStringA("Password")))); if (password == NULL || mir_strlen(password) == 0) { CToxPasswordEditor passwordEditor(this); @@ -71,7 +71,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) } uint8_t *encryptedData = (uint8_t*)mir_calloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH); TOX_ERR_DECRYPTION coreDecryptError; - if (!tox_pass_decrypt(data, size, (uint8_t*)password, mir_strlen(password), encryptedData, &coreDecryptError)) + if (!tox_pass_decrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), encryptedData, &coreDecryptError)) { ShowNotification(TranslateT("Unable to decrypt Tox profile"), MB_ICONERROR); debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError); @@ -98,15 +98,18 @@ void CToxProto::SaveToxProfile() { mir_cslock locker(profileLock); - size_t size = tox_get_savedata_size(tox); + if (!toxThread) + return; + + size_t size = tox_get_savedata_size(toxThread->tox); uint8_t *data = (uint8_t*)mir_calloc(size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH); - tox_get_savedata(tox, data); + tox_get_savedata(toxThread->tox, data); - size_t passwordLen = mir_strlen(password); - if (password && passwordLen) + pass_ptrA password(mir_utf8encodeW(pass_ptrT(getTStringA("Password")))); + if (password && mir_strlen(password)) { TOX_ERR_ENCRYPTION coreEncryptError; - if (!tox_pass_encrypt(data, size, (uint8_t*)password, passwordLen, data, &coreEncryptError)) + if (!tox_pass_encrypt(data, size, (uint8_t*)(char*)password, mir_strlen(password), data, &coreEncryptError)) { debugLogA(__FUNCTION__": failed to encrypt tox profile"); mir_free(data); @@ -159,12 +162,9 @@ CToxPasswordEditor::CToxPasswordEditor(CToxProto *proto) : void CToxPasswordEditor::OnOk(CCtrlButton*) { - ptrT tszPassword(password.GetText()); + pass_ptrT tszPassword(password.GetText()); if (savePermanently.Enabled()) m_proto->setTString("Password", tszPassword); - if (m_proto->password != NULL) - mir_free(m_proto->password); - m_proto->password = mir_utf8encodeW(tszPassword); EndDialog(m_hwnd, 1); } -- cgit v1.2.3