From 2e31328cb95f04bba6eed36efec3539bf54c6b0f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 23 Nov 2017 20:12:31 +0300 Subject: we need the additional lock to prevent the list from corruption --- src/mir_app/src/database.h | 2 +- src/mir_app/src/mdatabasecache.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mir_app/src/database.h b/src/mir_app/src/database.h index ec052b2f31..f5c793d94a 100644 --- a/src/mir_app/src/database.h +++ b/src/mir_app/src/database.h @@ -27,7 +27,7 @@ class MDatabaseCache : public MIDatabaseCache char* m_lastSetting; size_t m_contactSize; DBCachedContact *m_lastVL; - mir_cs m_cs; + mir_cs m_csContact, m_csVal; LIST m_lContacts; LIST m_lGlobalSettings; diff --git a/src/mir_app/src/mdatabasecache.cpp b/src/mir_app/src/mdatabasecache.cpp index c4b9e8d946..6d62c3d49b 100644 --- a/src/mir_app/src/mdatabasecache.cpp +++ b/src/mir_app/src/mdatabasecache.cpp @@ -59,7 +59,7 @@ MDatabaseCache::~MDatabaseCache() DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID) { - mir_cslock lck(m_cs); + mir_cslock lck(m_csContact); int index = m_lContacts.getIndex((DBCachedContact*)&contactID); if (index != -1) @@ -74,7 +74,7 @@ DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID) DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID) { - mir_cslock lck(m_cs); + mir_cslock lck(m_csContact); int index = m_lContacts.getIndex((DBCachedContact*)&contactID); return (index == -1) ? nullptr : m_lContacts[index]; @@ -82,13 +82,13 @@ DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID) DBCachedContact* MDatabaseCache::GetFirstContact() { - mir_cslock lck(m_cs); + mir_cslock lck(m_csContact); return m_lContacts[0]; } DBCachedContact* MDatabaseCache::GetNextContact(MCONTACT contactID) { - mir_cslock lck(m_cs); + mir_cslock lck(m_csContact); int index = m_lContacts.getIndex((DBCachedContact*)&contactID); return (index == -1) ? nullptr : m_lContacts[index+1]; @@ -96,7 +96,7 @@ DBCachedContact* MDatabaseCache::GetNextContact(MCONTACT contactID) void MDatabaseCache::FreeCachedContact(MCONTACT contactID) { - mir_cslock lck(m_cs); + mir_cslock lck(m_csContact); int index = m_lContacts.getIndex((DBCachedContact*)&contactID); if (index == -1) @@ -124,7 +124,10 @@ char* MDatabaseCache::InsertCachedSetting(const char* szName, int cbLen) char* newValue = (char*)HeapAlloc(m_hCacheHeap, 0, cbLen); *newValue++ = 0; mir_strcpy(newValue, szName); - m_lSettings.insert(newValue); + { + mir_cslock lck(m_csVal); + m_lSettings.insert(newValue); + } return newValue; } -- cgit v1.2.3