From 37edb76041ddaf7a500add3e49108a3106db43a8 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Thu, 16 Apr 2015 18:32:24 +0000 Subject: Tox: - Fixed memory leaks git-svn-id: http://svn.miranda-ng.org/main/trunk@12869 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_avatars.cpp | 1 + protocols/Tox/src/tox_contacts.cpp | 4 ++-- protocols/Tox/src/tox_options.cpp | 5 +++-- protocols/Tox/src/tox_profile.cpp | 5 +++-- protocols/Tox/src/tox_transfer.cpp | 24 ++++++++++++++---------- 5 files changed, 23 insertions(+), 16 deletions(-) (limited to 'protocols') diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index 1d9859f146..eb5bc71abb 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -44,6 +44,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) { fclose(hFile); debugLogA(__FUNCTION__": failed to read avatar file"); + mir_free(data); return; } fclose(hFile); diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 3afc60f0bb..3fa7c26580 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -457,7 +457,7 @@ INT_PTR CToxProto::UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar case PSN_INFOCHANGED: { MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - char *szProto = (hContact == NULL) ? szProto = proto->m_szModuleName : (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0); + char *szProto = (hContact == NULL) ? proto->m_szModuleName : GetContactProto(hContact); if (szProto == NULL) { break; @@ -473,7 +473,7 @@ INT_PTR CToxProto::UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar case PSN_APPLY: MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; - char *szProto = (hContact == NULL) ? szProto = proto->m_szModuleName : (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, hContact, 0); + char *szProto = (hContact == NULL) ? proto->m_szModuleName : GetContactProto(hContact); if (szProto == NULL) { break; diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 91b19d317a..82f1da61c4 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -63,6 +63,7 @@ void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*) SetClipboardData(CF_TEXT, hMemory); CloseClipboard(); } + mir_free(toxAddress); } void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) @@ -129,13 +130,13 @@ void CToxOptionsMain::ProfileExport_OnClick(CCtrlButton*) void CToxOptionsMain::OnApply() { - TCHAR *group = m_group.GetText(); + ptrT group(m_group.GetText()); if (mir_tstrlen(group) > 0 && Clist_GroupExists(group)) Clist_CreateGroup(0, group); if (m_proto->IsOnline()) { - CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_TCHAR, (LPARAM)m_nickname.GetText()); + CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_TCHAR, (LPARAM)ptrT(m_nickname.GetText())); if (m_proto->password != NULL) mir_free(m_proto->password); diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index afbf5f577e..2a22f24f90 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -154,11 +154,12 @@ CToxPasswordEditor::CToxPasswordEditor(CToxProto *proto) : void CToxPasswordEditor::OnOk(CCtrlButton*) { + ptrT tszPassword(password.GetText()); if (savePermanently.Enabled()) - m_proto->setTString("Password", password.GetText()); + m_proto->setTString("Password", tszPassword); if (m_proto->password != NULL) mir_free(m_proto->password); - m_proto->password = mir_utf8encodeW(password.GetText()); + m_proto->password = mir_utf8encodeW(tszPassword); EndDialog(m_hwnd, 1); } diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index cb2e3d7e0f..777671f418 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -138,11 +138,11 @@ void CToxProto::OnFileReceiveData(Tox*, uint32_t friendNumber, uint32_t fileNumb FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber); if (transfer == NULL) { - tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); +// tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); return; } - if (length == 0 || (length == 0 && position == UINT64_MAX)) + if (length == 0 || (position == UINT64_MAX)) { //receiving is finished proto->debugLogA(__FUNCTION__": finised the transfer of file (%d)", fileNumber); @@ -186,12 +186,6 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **pp if (friendNumber == UINT32_MAX) return NULL; - TCHAR *fileName = _tcsrchr(ppszFiles[0], '\\') + 1; - - size_t fileDirLength = fileName - ppszFiles[0]; - TCHAR *fileDir = (TCHAR*)mir_alloc(sizeof(TCHAR)*(fileDirLength + 1)); - _tcsncpy(fileDir, ppszFiles[0], fileDirLength); - fileDir[fileDirLength] = '\0'; FILE *hFile = _tfopen(ppszFiles[0], _T("rb")); if (hFile == NULL) @@ -200,6 +194,12 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **pp return NULL; } + TCHAR *fileName = _tcsrchr(ppszFiles[0], '\\') + 1; + size_t fileDirLength = fileName - ppszFiles[0]; + TCHAR *fileDir = (TCHAR*)mir_alloc(sizeof(TCHAR)*(fileDirLength + 1)); + _tcsncpy(fileDir, ppszFiles[0], fileDirLength); + fileDir[fileDirLength] = '\0'; + _fseeki64(hFile, 0, SEEK_END); uint64_t fileSize = _ftelli64(hFile); rewind(hFile); @@ -210,6 +210,8 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **pp if (sendError != TOX_ERR_FILE_SEND_OK) { debugLogA(__FUNCTION__": failed to send file (%d)", sendError); + mir_free(fileDir); + mir_free(name); return NULL; } @@ -218,7 +220,8 @@ HANDLE CToxProto::OnSendFile(MCONTACT hContact, const PROTOCHAR*, PROTOCHAR **pp transfer->pfts.tszWorkingDir = fileDir; transfer->hFile = hFile; transfers.Add(transfer); - + + mir_free(name); return (HANDLE)transfer; } @@ -229,7 +232,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber); if (transfer == NULL) { - tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); +// tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); return; } @@ -259,6 +262,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, proto->ProtoBroadcastAck(transfer->pfts.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)transfer, 0); transfer->status = FAILED; tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL); + mir_free(data); return; } -- cgit v1.2.3