summaryrefslogtreecommitdiff
path: root/plugins/Sessions/Src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-17 08:35:51 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-17 08:35:51 +0000
commitee2e419778605a5445474a33a29f2cfbb7eed245 (patch)
tree404194e1d202f6433693f3833792e940c04e2d7e /plugins/Sessions/Src
parent1ca120b165c2f2d9f521a04bfc31c7956d2ce422 (diff)
bunch of fixes for various memory-related problems
git-svn-id: http://svn.miranda-ng.org/main/trunk@1001 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Sessions/Src')
-rw-r--r--plugins/Sessions/Src/Utils.cpp75
1 files changed, 33 insertions, 42 deletions
diff --git a/plugins/Sessions/Src/Utils.cpp b/plugins/Sessions/Src/Utils.cpp
index 26adc41513..8ac041e7e9 100644
--- a/plugins/Sessions/Src/Utils.cpp
+++ b/plugins/Sessions/Src/Utils.cpp
@@ -146,34 +146,24 @@ void SetSessionMark(HANDLE hContact,int mode,char bit,unsigned int marknum)
BOOL LoadContactsFromMask(HANDLE hContact,int mode,int count)
{
- if(mode==0)
- {
+ if (mode == 0) {
DBVARIANT dbv;
- if (!DBGetContactSettingString(hContact, __INTERNAL_NAME, "LastSessionsMarks", &dbv) && dbv.pszVal)
- {
- if (dbv.pszVal[count]=='1')
- {
- DBFreeVariant(&dbv);
- return 1;
- }
- }
- else
+ if ( DBGetContactSettingString(hContact, __INTERNAL_NAME, "LastSessionsMarks", &dbv))
return 0;
+
+ BOOL res = dbv.pszVal[count] == '1';
+ DBFreeVariant(&dbv);
+ return res;
}
- if (mode==1)
- {
+ if (mode == 1) {
DBVARIANT dbv;
- if (!DBGetContactSettingString(hContact, __INTERNAL_NAME, "UserSessionsMarks", &dbv) && dbv.pszVal)
- {
- if (dbv.pszVal[count]=='1')
- {
- DBFreeVariant(&dbv);
- return 1;
- }
- }
- else
+ if ( DBGetContactSettingString(hContact, __INTERNAL_NAME, "UserSessionsMarks", &dbv))
return 0;
+
+ BOOL res = dbv.pszVal[count] == '1';
+ DBFreeVariant(&dbv);
+ return res;
}
return 0;
}
@@ -194,7 +184,7 @@ void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
if(mode==0)
{
DBVARIANT dbv;
- if (!DBGetContactSettingString(hContact, __INTERNAL_NAME, "LastSessionsOrder", &dbv) && dbv.pszVal)
+ if (!DBGetContactSettingString(hContact, __INTERNAL_NAME, "LastSessionsOrder", &dbv))
{
char* temp=NULL;
char* temp2=NULL;
@@ -351,27 +341,28 @@ BOOL ResaveSettings(char* szName,int iFirst,int iLimit,TCHAR* szBuffer)
for (int i = iFirst; i < iLimit; i++)
{
- if (szBuffer)
- {
- DBVARIANT dbv_temp = {0};
- mir_snprintf(szNameBuf, SIZEOF(szNameBuf), "%s_%u", szName, i);
- DBGetContactSettingTString(NULL, __INTERNAL_NAME, szNameBuf, &dbv_temp);
- DBWriteContactSettingTString(NULL, __INTERNAL_NAME, szNameBuf, szBuffer);
- marked=IsMarkedUserDefSession(i);
- MarkUserDefSession(i,(BYTE)((i==iFirst)?IsMarkedUserDefSession(iFirst-1):marked_t));
- marked_t=marked;
- mir_free(szBuffer);
- if (dbv_temp.ptszVal)
- {
- szBuffer = mir_tstrdup(dbv_temp.ptszVal);
- DBFreeVariant(&dbv_temp);
- }
- else
- return 0;
- }
- else
+ if (szBuffer == NULL)
break;
+
+ mir_snprintf(szNameBuf, SIZEOF(szNameBuf), "%s_%u", szName, i);
+
+ DBVARIANT dbv_temp;
+ int res = DBGetContactSettingTString(NULL, __INTERNAL_NAME, szNameBuf, &dbv_temp);
+ DBWriteContactSettingTString(NULL, __INTERNAL_NAME, szNameBuf, szBuffer);
+ mir_free(szBuffer);
+
+ marked = IsMarkedUserDefSession(i);
+ MarkUserDefSession(i,(BYTE)((i==iFirst)?IsMarkedUserDefSession(iFirst-1):marked_t));
+ marked_t = marked;
+
+ if (res) // read failed
+ return 0;
+
+ szBuffer = mir_tstrdup(dbv_temp.ptszVal);
+ DBFreeVariant(&dbv_temp);
}
+
+ mir_free(szBuffer);
return 1;
}