From 976508f30d0579e05d8ccd53be903b3cda89f508 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 18 Mar 2013 11:51:38 +0000 Subject: various memory allocation problems git-svn-id: http://svn.miranda-ng.org/main/trunk@4090 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/IEView/src/TabSRMMHTMLBuilder.cpp | 4 +- plugins/Msg_Export/src/utils.cpp | 15 +-- plugins/SeenPlugin/src/main.cpp | 9 +- plugins/SeenPlugin/src/seen.h | 15 ++- plugins/SeenPlugin/src/utils.cpp | 132 +++++++++++--------------- plugins/TabSRMM/src/themes.cpp | 8 +- plugins/TrafficCounter/src/TrafficCounter.cpp | 6 +- 7 files changed, 78 insertions(+), 111 deletions(-) (limited to 'plugins') diff --git a/plugins/IEView/src/TabSRMMHTMLBuilder.cpp b/plugins/IEView/src/TabSRMMHTMLBuilder.cpp index aad617fd6d..f407dd62b4 100644 --- a/plugins/IEView/src/TabSRMMHTMLBuilder.cpp +++ b/plugins/IEView/src/TabSRMMHTMLBuilder.cpp @@ -429,9 +429,9 @@ void TabSRMMHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event free(output); } } - if (szRealProto!=NULL) delete szRealProto; + + mir_free(szRealProto); view->documentClose(); -// view->scrollToBottom(); } void TabSRMMHTMLBuilder::appendEvent(IEView *view, IEVIEWEVENT *event) { diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index b2339b8ec6..a2accf6a7d 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -540,16 +540,12 @@ bool bWriteHexToFile( HANDLE hFile, void * pData, int nSize ) // Developer : KN ///////////////////////////////////////////////////////////////////// - bool bReadMirandaDirAndPath() { - TCHAR szDBPath[MAX_PATH]; - char tmp[MAX_PATH]; - TCHAR *tmp2; - _tcscpy( szDBPath, pszDbPathError ); - PathToAbsolute("miranda32.exe", tmp); - tmp2 = mir_utf8decodeT(tmp); - sMirandaPath = tmp2; + TCHAR szDBPath[MAX_PATH], tmp[MAX_PATH]; + _tcscpy(szDBPath, pszDbPathError); + PathToAbsoluteT( _T("miranda32.exe"), tmp); + sMirandaPath = tmp; sMirandaPath.erase(sMirandaPath.find_last_of(_T("\\"))); CallService(MS_DB_GETPROFILEPATHT, (WPARAM)MAX_PATH - 1, (LPARAM)szDBPath); sDBPath = szDBPath; @@ -577,8 +573,7 @@ void ReplaceDBPath( tstring &sRet ) ReplaceAll( sRet, _T("%dbpath%"), sDBPath ); // Try to firure out if it is a relative path ( ..\..\MsgExport\ ) if (sRet.size() <= 2 || ! ( sRet[1] == ':' || - ( sRet[0] == '\\' && sRet[1] == '\\')) - ) + ( sRet[0] == '\\' && sRet[1] == '\\'))) { // Relative path // we will prepend the mirande exe path to avoid problems diff --git a/plugins/SeenPlugin/src/main.cpp b/plugins/SeenPlugin/src/main.cpp index 650382c8b6..9dd4e7ea1c 100644 --- a/plugins/SeenPlugin/src/main.cpp +++ b/plugins/SeenPlugin/src/main.cpp @@ -47,15 +47,10 @@ DBVTranslation idleTr[TRANSNUMBER]={ }; BOOL includeIdle; -logthread_info **contactQueue = NULL; -int contactQueueSize = 0; +LIST arContacts(16, LIST::FTSortFunc(HandleKeySortT)); int MainInit(WPARAM wparam,LPARAM lparam) { - contactQueueSize = 16*sizeof(logthread_info *); - contactQueue = (logthread_info **)malloc(contactQueueSize); - memset(&contactQueue[0], 0, contactQueueSize); - contactQueueSize = 16; includeIdle = (BOOL )db_get_b(NULL,S_MOD,"IdleSupport",1); HookEvent(ME_OPT_INITIALISE, OptionsInit); @@ -84,7 +79,6 @@ int MainInit(WPARAM wparam,LPARAM lparam) CallService("DBEditorpp/RegisterSingleModule", (WPARAM)S_MOD, 0); db_set_s(NULL,"Uninstall",Translate("Last seen"),S_MOD); - if ( ServiceExists(MS_TIPPER_ADDTRANSLATION)) for (int i=0; i < TRANSNUMBER; i++) CallService(MS_TIPPER_ADDTRANSLATION, 0, (LPARAM)&idleTr[i]); @@ -119,6 +113,7 @@ extern "C" __declspec(dllexport) int Unload(void) if (ehmissed) UnhookEvent(ehmissed); + arContacts.destroy(); CloseHandle(g_hShutdownEvent); UninitMenuitem(); return 0; diff --git a/plugins/SeenPlugin/src/seen.h b/plugins/SeenPlugin/src/seen.h index 9c2e1adc55..1a07999868 100644 --- a/plugins/SeenPlugin/src/seen.h +++ b/plugins/SeenPlugin/src/seen.h @@ -109,19 +109,18 @@ int CheckIfOnline(void); void UninitMenuitem(); void ShowHistory(HANDLE hContact, BYTE isAlert); -typedef struct logthread_info { - char sProtoName[MAXMODULELABELLENGTH]; - HANDLE hContact; - WORD courStatus; - int queueIndex; -} logthread_info; +struct logthread_info +{ + HANDLE hContact; + char sProtoName[MAXMODULELABELLENGTH]; + WORD currStatus; +}; extern HINSTANCE hInstance; -extern logthread_info **contactQueue; -extern int contactQueueSize; extern DWORD StatusColors15bits[]; extern BOOL includeIdle; extern HANDLE ehmissed; extern HANDLE ehuserinfo, hmenuitem, ehmissed_proto; extern DWORD dwmirver; +extern LIST arContacts; \ No newline at end of file diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index 8eb1f01f37..e22fff1911 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -512,7 +512,8 @@ void ShowPopup(HANDLE hcontact, const char * lpzProto, int newStatus) PUAddPopUpT(&ppd); } -void myPlaySound(HANDLE hcontact, WORD newStatus, WORD oldStatus){ +void myPlaySound(HANDLE hcontact, WORD newStatus, WORD oldStatus) +{ if (CallService(MS_IGNORE_ISIGNORED,(WPARAM)hcontact,IGNOREEVENT_USERONLINE)) return; //oldStatus and hcontact are not used yet char * soundname=0; @@ -523,45 +524,17 @@ void myPlaySound(HANDLE hcontact, WORD newStatus, WORD oldStatus){ if (soundname!=0) SkinPlaySound(soundname); } -//will give hContact position or zero -int isContactQueueActive(HANDLE hContact){ - int i = 0; - if (!hContact) { -// MessageBox(0,"Is myself in the queue: never","LastSeen-Mod",0); - return 0; - } - for (i=1;ihContact==hContact) return i; - } - return 0; -} - //will add hContact to queue and will return position; -int addContactToQueue(HANDLE hContact){ +static logthread_info* addContactToQueue(HANDLE hContact) +{ int i = 0; - if (!hContact) { -// MessageBox(0,"Adding myself to queue","LastSeen-Mod",0); - return 0; - } - for (i=1;iqueueIndex = i; - contactQueue[i]->hContact = hContact; - return i; - } - } - //no free space. Create some - //MessageBox(0,"Creating more space","LastSeen-Mod",0); - contactQueue = (logthread_info **)realloc(contactQueue,(contactQueueSize+16)*sizeof(logthread_info *)); - memset(&contactQueue[contactQueueSize],0, 16*sizeof(logthread_info *)); - i = contactQueueSize; - contactQueue[i] = (logthread_info *)malloc(sizeof(logthread_info)); - contactQueue[i]->queueIndex = i; - contactQueue[i]->hContact = hContact; - contactQueueSize += 16; - return i; + if (!hContact) + return NULL; + + logthread_info *p = (logthread_info*)mir_calloc(sizeof(logthread_info)); + p->hContact = hContact; + arContacts.insert(p); + return p; } static void waitThread(void *param) @@ -569,36 +542,41 @@ static void waitThread(void *param) logthread_info* infoParam = (logthread_info*)param; WORD prevStatus = db_get_w(infoParam->hContact,S_MOD,"StatusTriger",ID_STATUS_OFFLINE); - Sleep(1500); // I hope in 1.5 second all the needed info will be set - if (includeIdle) - if (db_get_dw(infoParam->hContact,infoParam->sProtoName,"IdleTS",0)) - infoParam->courStatus &=0x7FFF; - - if (infoParam->courStatus != prevStatus){ - db_set_w(infoParam->hContact,S_MOD,"OldStatus",(WORD)(prevStatus|0x8000)); + + // I hope in 1.5 second all the needed info will be set + if ( WaitForSingleObject(g_hShutdownEvent, 1500) == WAIT_TIMEOUT) { if (includeIdle) - db_set_b(infoParam->hContact,S_MOD,"OldIdle",(BYTE)((prevStatus&0x8000)==0)); + if (db_get_dw(infoParam->hContact,infoParam->sProtoName,"IdleTS",0)) + infoParam->currStatus &=0x7FFF; + + if (infoParam->currStatus != prevStatus){ + db_set_w(infoParam->hContact,S_MOD,"OldStatus",(WORD)(prevStatus|0x8000)); + if (includeIdle) + db_set_b(infoParam->hContact,S_MOD,"OldIdle",(BYTE)((prevStatus&0x8000)==0)); - db_set_w(infoParam->hContact,S_MOD,"StatusTriger",infoParam->courStatus); + db_set_w(infoParam->hContact,S_MOD,"StatusTriger",infoParam->currStatus); + } } - contactQueue[infoParam->queueIndex] = 0; - free(infoParam); + arContacts.remove(infoParam); + mir_free(infoParam); } int UpdateValues(WPARAM wparam,LPARAM lparam) { // to make this code faster if (!wparam) return 0; + + HANDLE hContact = (HANDLE)wparam; DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING *)lparam; //if (CallService(MS_IGNORE_ISIGNORED,(WPARAM)hContact,IGNOREEVENT_USERONLINE)) return 0; BOOL isIdleEvent = includeIdle?(strcmp(cws->szSetting,"IdleTS")==0):0; if (strcmp(cws->szSetting,"Status") && strcmp(cws->szSetting,"StatusTriger") && (isIdleEvent==0)) return 0; if (!strcmp(cws->szModule,S_MOD)) { //here we will come when Settings/SeenModule/StatusTriger is changed - WORD prevStatus=db_get_w((HANDLE)wparam, S_MOD, "OldStatus", ID_STATUS_OFFLINE); + WORD prevStatus=db_get_w(hContact, S_MOD, "OldStatus", ID_STATUS_OFFLINE); if (includeIdle){ - if ( db_get_b((HANDLE)wparam, S_MOD, "OldIdle", 0)) prevStatus &= 0x7FFF; + if ( db_get_b(hContact, S_MOD, "OldIdle", 0)) prevStatus &= 0x7FFF; else prevStatus |= 0x8000; } if ((cws->value.wVal|0x8000)<=ID_STATUS_OFFLINE) @@ -607,8 +585,8 @@ int UpdateValues(WPARAM wparam,LPARAM lparam) // avoid repeating the offline status if ((prevStatus|0x8000)<=ID_STATUS_OFFLINE) return 0; - proto = GetContactProto((HANDLE)wparam); - db_set_b((HANDLE)wparam, S_MOD, "Offline", 1); + proto = GetContactProto(hContact); + db_set_b(hContact, S_MOD, "Offline", 1); { DWORD t; char *str = (char *)malloc(MAXMODULELABELLENGTH+9); @@ -616,57 +594,57 @@ int UpdateValues(WPARAM wparam,LPARAM lparam) t = db_get_dw(NULL,S_MOD,str,0); if (!t) t = time(NULL); free(str); - DBWriteTimeTS(t, (HANDLE)wparam); + DBWriteTimeTS(t, hContact); } if (!db_get_b(NULL,S_MOD,"IgnoreOffline",1)) { if ( db_get_b(NULL,S_MOD,"FileOutput",0)) - FileWrite((HANDLE)wparam); + FileWrite(hContact); - char *sProto = GetContactProto((HANDLE)wparam); + char *sProto = GetContactProto(hContact); if (CallProtoService(sProto, PS_GETSTATUS, 0, 0) > ID_STATUS_OFFLINE) { - myPlaySound((HANDLE)wparam, ID_STATUS_OFFLINE, prevStatus); + myPlaySound(hContact, ID_STATUS_OFFLINE, prevStatus); if ( db_get_b(NULL, S_MOD, "UsePopups", 0)) - ShowPopup((HANDLE)wparam, sProto, ID_STATUS_OFFLINE); + ShowPopup(hContact, sProto, ID_STATUS_OFFLINE); } if ( db_get_b(NULL, S_MOD, "KeepHistory", 0)) - HistoryWrite((HANDLE)wparam); + HistoryWrite(hContact); - if ( db_get_b((HANDLE)wparam, S_MOD, "OnlineAlert", 0)) - ShowHistory((HANDLE)wparam, 1); + if ( db_get_b(hContact, S_MOD, "OnlineAlert", 0)) + ShowHistory(hContact, 1); } } else { - if (cws->value.wVal==prevStatus && !db_get_b((HANDLE)wparam, S_MOD, "Offline", 0)) + if (cws->value.wVal==prevStatus && !db_get_b(hContact, S_MOD, "Offline", 0)) return 0; - DBWriteTimeTS(time(NULL), (HANDLE)wparam); + DBWriteTimeTS(time(NULL), hContact); //db_set_w(hContact,S_MOD,"StatusTriger",(WORD)cws->value.wVal); - if ( db_get_b(NULL, S_MOD, "FileOutput", 0)) FileWrite((HANDLE)wparam); - if (prevStatus != cws->value.wVal) myPlaySound((HANDLE)wparam, cws->value.wVal, prevStatus); + if ( db_get_b(NULL, S_MOD, "FileOutput", 0)) FileWrite(hContact); + if (prevStatus != cws->value.wVal) myPlaySound(hContact, cws->value.wVal, prevStatus); if ( db_get_b(NULL, S_MOD, "UsePopups", 0)) if (prevStatus != cws->value.wVal) - ShowPopup((HANDLE)wparam, GetContactProto((HANDLE)wparam), cws->value.wVal|0x8000); + ShowPopup(hContact, GetContactProto(hContact), cws->value.wVal|0x8000); - if ( db_get_b(NULL, S_MOD, "KeepHistory", 0)) HistoryWrite((HANDLE)wparam); - if ( db_get_b((HANDLE)wparam, S_MOD, "OnlineAlert", 0)) ShowHistory((HANDLE)wparam, 1); - db_set_b((HANDLE)wparam, S_MOD, "Offline", 0); + if ( db_get_b(NULL, S_MOD, "KeepHistory", 0)) HistoryWrite(hContact); + if ( db_get_b(hContact, S_MOD, "OnlineAlert", 0)) ShowHistory(hContact, 1); + db_set_b(hContact, S_MOD, "Offline", 0); } } else if (IsWatchedProtocol(cws->szModule)) { //here we will come when //Status is changed or it is idle event and if is watched - if (CallProtoService(cws->szModule,PS_GETSTATUS,0,0)>ID_STATUS_OFFLINE){ - int index; - if (!(index = isContactQueueActive((HANDLE)wparam))) { - index = addContactToQueue((HANDLE)wparam); - strncpy(contactQueue[index]->sProtoName,cws->szModule,MAXMODULELABELLENGTH); - mir_forkthread(waitThread, contactQueue[index]); + if ( CallProtoService(cws->szModule,PS_GETSTATUS,0,0) > ID_STATUS_OFFLINE){ + logthread_info *p = arContacts.find((logthread_info*)&hContact); + if (p == NULL) { + p = addContactToQueue(hContact); + strncpy(p->sProtoName, cws->szModule, MAXMODULELABELLENGTH); + mir_forkthread(waitThread, p); } - contactQueue[index]->courStatus = isIdleEvent ? db_get_w((HANDLE)wparam, cws->szModule, "Status", ID_STATUS_OFFLINE) : cws->value.wVal; + p->currStatus = isIdleEvent ? db_get_w(hContact, cws->szModule, "Status", ID_STATUS_OFFLINE) : cws->value.wVal; } } return 0; @@ -725,7 +703,7 @@ int ModeChange(WPARAM wparam,LPARAM lparam) logthread_info *info = (logthread_info *)malloc(sizeof(logthread_info)); strncpy(info->sProtoName,courProtoName,MAXMODULELABELLENGTH); info->hContact = 0; - info->courStatus = 0; + info->currStatus = 0; mir_forkthread(cleanThread, info); } diff --git a/plugins/TabSRMM/src/themes.cpp b/plugins/TabSRMM/src/themes.cpp index 25c50b49cc..f2c0a8e1f3 100644 --- a/plugins/TabSRMM/src/themes.cpp +++ b/plugins/TabSRMM/src/themes.cpp @@ -1233,10 +1233,11 @@ void CSkin::Unload() m_closeIcon = m_maxIcon = m_minIcon = 0; - for (i=0; i < m_nrSkinIcons; i++) { + for (i=0; i < m_nrSkinIcons; i++) if (m_skinIcons[i].phIcon ) ::DestroyIcon(*(m_skinIcons[i].phIcon)); - } + mir_free(m_skinIcons); + M->getAeroState(); // refresh after unload ::FreeTabConfig(); ::ReloadTabConfig(); @@ -1587,9 +1588,8 @@ void CSkin::LoadItems() CImageItem *pItem = m_ImageItems; if (m_skinIcons == NULL) - m_skinIcons = (TIconDescW *)malloc(sizeof(TIconDescW) * NR_MAXSKINICONS); + m_skinIcons = (TIconDescW *)mir_calloc(sizeof(TIconDescW) * NR_MAXSKINICONS); - ZeroMemory(m_skinIcons, sizeof(TIconDesc) * NR_MAXSKINICONS); m_nrSkinIcons = 0; szSections = (TCHAR *)malloc((SECT_BUFFER_SIZE + 2) * sizeof(TCHAR)); diff --git a/plugins/TrafficCounter/src/TrafficCounter.cpp b/plugins/TrafficCounter/src/TrafficCounter.cpp index 994752626b..81ad671711 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.cpp +++ b/plugins/TrafficCounter/src/TrafficCounter.cpp @@ -1206,14 +1206,14 @@ void CreateProtocolList(void) void DestroyProtocolList(void) { - for (int i = 0; i < NumberOfAccounts; i++) - { + for (int i = 0; i < NumberOfAccounts; i++) { Stat_CheckStatistics(i); CloseHandle(ProtoList[i].hFile); + mir_free(ProtoList[i].tszAccountName); mir_free(ProtoList[i].name); mir_free(ProtoList[i].AllStatistics); } - // + mir_free(ProtoList); } -- cgit v1.2.3