From 81f73a9df3f62a65d2c3f9c1d2033bca1f66acf0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 31 Dec 2014 11:08:53 +0000 Subject: misplaced lock for database cache access git-svn-id: http://svn.miranda-ng.org/main/trunk@11693 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/dbsettings.cpp | 86 ++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'plugins') diff --git a/plugins/Db3x_mmap/src/dbsettings.cpp b/plugins/Db3x_mmap/src/dbsettings.cpp index 82f65d627e..a2175e6f8b 100644 --- a/plugins/Db3x_mmap/src/dbsettings.cpp +++ b/plugins/Db3x_mmap/src/dbsettings.cpp @@ -722,56 +722,58 @@ STDMETHODIMP_(BOOL) CDb3Mmap::DeleteContactSetting(MCONTACT contactID, LPCSTR sz } MCONTACT saveContact = contactID; - char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen); - if (szCachedSettingName[-1] == 0) { // it's not a resident variable + { mir_cslock lck(m_csDbAccess); - DWORD ofsModuleName = GetModuleNameOfs(szModule); - DWORD ofsContact = GetContactOffset(contactID); - DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); - if (dbc->signature != DBCONTACT_SIGNATURE) - return 1; + char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen); + if (szCachedSettingName[-1] == 0) { // it's not a resident variable + DWORD ofsModuleName = GetModuleNameOfs(szModule); + DWORD ofsContact = GetContactOffset(contactID); + DBContact *dbc = (DBContact*)DBRead(ofsContact, NULL); + if (dbc->signature != DBCONTACT_SIGNATURE) + return 1; - // make sure the module group exists - DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc, ofsModuleName); - if (ofsSettingsGroup == 0) - return 1; + // make sure the module group exists + DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(dbc, ofsModuleName); + if (ofsSettingsGroup == 0) + return 1; - // find if the setting exists - DWORD ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob); - int bytesRemaining; - PBYTE pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); - while (pBlob[0]) { - NeedBytes(settingNameLen + 1); - if (pBlob[0] == settingNameLen && !memcmp(pBlob + 1, szSetting, settingNameLen)) - break; - NeedBytes(1); - MoveAlong(pBlob[0] + 1); - NeedBytes(3); - MoveAlong(1 + GetSettingValueLength(pBlob)); - NeedBytes(1); - } - if (!pBlob[0]) //setting didn't exist - return 1; + // find if the setting exists + DWORD ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob); + int bytesRemaining; + PBYTE pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); + while (pBlob[0]) { + NeedBytes(settingNameLen + 1); + if (pBlob[0] == settingNameLen && !memcmp(pBlob + 1, szSetting, settingNameLen)) + break; + NeedBytes(1); + MoveAlong(pBlob[0] + 1); + NeedBytes(3); + MoveAlong(1 + GetSettingValueLength(pBlob)); + NeedBytes(1); + } + if (!pBlob[0]) //setting didn't exist + return 1; - // bin it - MoveAlong(1 + settingNameLen); - NeedBytes(3); - int nameLen = 1 + settingNameLen; - int valLen = 1 + GetSettingValueLength(pBlob); - DWORD ofsSettingToCut = ofsBlobPtr - nameLen; - MoveAlong(valLen); - NeedBytes(1); - while (pBlob[0]) { - MoveAlong(pBlob[0] + 1); + // bin it + MoveAlong(1 + settingNameLen); NeedBytes(3); - MoveAlong(1 + GetSettingValueLength(pBlob)); + int nameLen = 1 + settingNameLen; + int valLen = 1 + GetSettingValueLength(pBlob); + DWORD ofsSettingToCut = ofsBlobPtr - nameLen; + MoveAlong(valLen); NeedBytes(1); + while (pBlob[0]) { + MoveAlong(pBlob[0] + 1); + NeedBytes(3); + MoveAlong(1 + GetSettingValueLength(pBlob)); + NeedBytes(1); + } + DBMoveChunk(ofsSettingToCut, ofsSettingToCut + nameLen + valLen, ofsBlobPtr + 1 - ofsSettingToCut); + DBFlush(1); } - DBMoveChunk(ofsSettingToCut, ofsSettingToCut + nameLen + valLen, ofsBlobPtr + 1 - ofsSettingToCut); - DBFlush(1); - } - m_cache->GetCachedValuePtr(saveContact, szCachedSettingName, -1); + m_cache->GetCachedValuePtr(saveContact, szCachedSettingName, -1); + } // notify DBCONTACTWRITESETTING dbcws = { 0 }; -- cgit v1.2.3