summaryrefslogtreecommitdiff
path: root/protocols/IcqOscarJ/src/cookies.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-05-13 20:27:01 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-05-13 20:27:01 +0000
commit690f3c5828685ffc3c2a11d8d68e4c0b1cf5f0ba (patch)
tree6fe6df105c8ffcefb5e3c0bfe59b14bfa2d1acbe /protocols/IcqOscarJ/src/cookies.cpp
parent37c98eaad76b7f1bf86c75fe2c32cf6aa11f7c6f (diff)
major memory leak in ICQ cookie module
git-svn-id: http://svn.miranda-ng.org/main/trunk@16829 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IcqOscarJ/src/cookies.cpp')
-rw-r--r--protocols/IcqOscarJ/src/cookies.cpp86
1 files changed, 37 insertions, 49 deletions
diff --git a/protocols/IcqOscarJ/src/cookies.cpp b/protocols/IcqOscarJ/src/cookies.cpp
index a18fdc7f87..77aaa6b001 100644
--- a/protocols/IcqOscarJ/src/cookies.cpp
+++ b/protocols/IcqOscarJ/src/cookies.cpp
@@ -29,19 +29,13 @@
#include "stdafx.h"
-#define INVALID_COOKIE_INDEX -1
-
void CIcqProto::RemoveExpiredCookies()
{
time_t tNow = time(NULL);
- for (int i = cookies.getCount() - 1; i >= 0; i--) {
- icq_cookie_info *cookie = cookies[i];
- if ((cookie->dwTime + COOKIE_TIMEOUT) < tNow) {
+ for (int i = cookies.getCount() - 1; i >= 0; i--)
+ if ((cookies[i].dwTime + COOKIE_TIMEOUT) < tNow)
cookies.remove(i);
- SAFE_FREE((void**)&cookie);
- }
- }
}
// Generate and allocate cookie
@@ -53,15 +47,14 @@ DWORD CIcqProto::AllocateCookie(BYTE bType, WORD wIdent, MCONTACT hContact, void
dwThisSeq &= 0x7FFF;
dwThisSeq |= wIdent << 0x10;
- icq_cookie_info* p = (icq_cookie_info*)SAFE_MALLOC(sizeof(icq_cookie_info));
- if (p) {
- p->bType = bType;
- p->dwCookie = dwThisSeq;
- p->hContact = hContact;
- p->pvExtra = pvExtra;
- p->dwTime = time(NULL);
- cookies.insert(p);
- }
+ icq_cookie_info *p = new icq_cookie_info();
+ p->bType = bType;
+ p->dwCookie = dwThisSeq;
+ p->hContact = hContact;
+ p->pvExtra = pvExtra;
+ p->dwTime = time(NULL);
+ cookies.insert(p);
+
return dwThisSeq;
}
@@ -80,8 +73,8 @@ int CIcqProto::GetCookieType(DWORD dwCookie)
mir_cslock l(cookieMutex);
int i = cookies.getIndex((icq_cookie_info*)&dwCookie);
- if (i != INVALID_COOKIE_INDEX)
- i = cookies[i]->bType;
+ if (i != -1)
+ i = cookies[i].bType;
return i;
}
@@ -91,11 +84,11 @@ int CIcqProto::FindCookie(DWORD dwCookie, MCONTACT *phContact, void **ppvExtra)
mir_cslock l(cookieMutex);
int i = cookies.getIndex((icq_cookie_info*)&dwCookie);
- if (i != INVALID_COOKIE_INDEX) {
+ if (i != -1) {
if (phContact)
- *phContact = cookies[i]->hContact;
+ *phContact = cookies[i].hContact;
if (ppvExtra)
- *ppvExtra = cookies[i]->pvExtra;
+ *ppvExtra = cookies[i].pvExtra;
// Cookie found
return 1;
@@ -109,11 +102,12 @@ int CIcqProto::FindCookieByData(void *pvExtra, DWORD *pdwCookie, MCONTACT *phCon
mir_cslock l(cookieMutex);
for (int i = 0; i < cookies.getCount(); i++) {
- if (pvExtra == cookies[i]->pvExtra) {
+ icq_cookie_info &cookie = cookies[i];
+ if (pvExtra == cookie.pvExtra) {
if (phContact)
- *phContact = cookies[i]->hContact;
+ *phContact = cookie.hContact;
if (pdwCookie)
- *pdwCookie = cookies[i]->dwCookie;
+ *pdwCookie = cookie.dwCookie;
// Cookie found
return 1;
@@ -123,18 +117,20 @@ int CIcqProto::FindCookieByData(void *pvExtra, DWORD *pdwCookie, MCONTACT *phCon
return 0;
}
-int CIcqProto::FindCookieByType(BYTE bType, DWORD *pdwCookie, MCONTACT *phContact, void** ppvExtra)
+int CIcqProto::FindCookieByType(BYTE bType, DWORD *pdwCookie, MCONTACT *phContact, void **ppvExtra)
{
mir_cslock l(cookieMutex);
for (int i = 0; i < cookies.getCount(); i++) {
- if (bType == cookies[i]->bType) {
+ icq_cookie_info &cookie = cookies[i];
+
+ if (bType == cookie.bType) {
if (pdwCookie)
- *pdwCookie = cookies[i]->dwCookie;
+ *pdwCookie = cookie.dwCookie;
if (phContact)
- *phContact = cookies[i]->hContact;
+ *phContact = cookie.hContact;
if (ppvExtra)
- *ppvExtra = cookies[i]->pvExtra;
+ *ppvExtra = cookie.pvExtra;
// Cookie found
return 1;
@@ -149,15 +145,16 @@ int CIcqProto::FindMessageCookie(DWORD dwMsgID1, DWORD dwMsgID2, DWORD *pdwCooki
mir_cslock l(cookieMutex);
for (int i = 0; i < cookies.getCount(); i++) {
- if (cookies[i]->bType == CKT_MESSAGE || cookies[i]->bType == CKT_FILE || cookies[i]->bType == CKT_REVERSEDIRECT) {
+ icq_cookie_info &cookie = cookies[i];
+ if (cookie.bType == CKT_MESSAGE || cookie.bType == CKT_FILE || cookie.bType == CKT_REVERSEDIRECT) {
// message cookie found
- cookie_message_data *pCookie = (cookie_message_data*)cookies[i]->pvExtra;
+ cookie_message_data *pCookie = (cookie_message_data*)cookie.pvExtra;
if (pCookie->dwMsgID1 == dwMsgID1 && pCookie->dwMsgID2 == dwMsgID2) {
if (phContact)
- *phContact = cookies[i]->hContact;
+ *phContact = cookie.hContact;
if (pdwCookie)
- *pdwCookie = cookies[i]->dwCookie;
+ *pdwCookie = cookie.dwCookie;
if (ppvExtra)
*ppvExtra = pCookie;
@@ -175,13 +172,8 @@ void CIcqProto::FreeCookie(DWORD dwCookie)
mir_cslock l(cookieMutex);
int i = cookies.getIndex((icq_cookie_info*)&dwCookie);
- if (i != INVALID_COOKIE_INDEX) {
- // Cookie found, remove from list
- icq_cookie_info *cookie = cookies[i];
-
+ if (i != -1) // Cookie found, remove from list
cookies.remove(i);
- SAFE_FREE((void**)&cookie);
- }
RemoveExpiredCookies();
}
@@ -191,11 +183,10 @@ void CIcqProto::FreeCookieByData(BYTE bType, void *pvExtra)
mir_cslock l(cookieMutex);
for (int i = 0; i < cookies.getCount(); i++) {
- icq_cookie_info *cookie = cookies[i];
- if (bType == cookie->bType && pvExtra == cookie->pvExtra) {
+ icq_cookie_info &cookie = cookies[i];
+ if (bType == cookie.bType && pvExtra == cookie.pvExtra) {
// Cookie found, remove from list
cookies.remove(i);
- SAFE_FREE((void**)&cookie);
break;
}
}
@@ -208,14 +199,11 @@ void CIcqProto::ReleaseCookie(DWORD dwCookie)
mir_cslock l(cookieMutex);
int i = cookies.getIndex(( icq_cookie_info* )&dwCookie );
- if (i != INVALID_COOKIE_INDEX) {
- // Cookie found, remove from list
- icq_cookie_info *cookie = cookies[i];
-
+ if (i != -1) { // Cookie found, remove from list
+ SAFE_FREE((void**)&cookies[i].pvExtra);
cookies.remove(i);
- SAFE_FREE((void**)&cookie->pvExtra);
- SAFE_FREE((void**)&cookie);
}
+
RemoveExpiredCookies();
}