From 81dd07b3ae0c7f31da0c6766b8b325e2601e4195 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 13 Apr 2018 19:28:30 +0300 Subject: fix for deadlock in AVS --- plugins/AVS/src/cache.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'plugins/AVS/src/cache.cpp') diff --git a/plugins/AVS/src/cache.cpp b/plugins/AVS/src/cache.cpp index bb04abaf2d..6b4ac7417e 100644 --- a/plugins/AVS/src/cache.cpp +++ b/plugins/AVS/src/cache.cpp @@ -75,20 +75,23 @@ CacheNode* FindAvatarInCache(MCONTACT hContact, bool add, bool findAny) if (szProto == nullptr || !db_get_b(NULL, AVS_MODULE, szProto, 1)) return nullptr; - mir_cslock lck(cachecs); - CacheNode *cc = arCache.find((CacheNode*)&hContact); - if (cc) { - cc->t_lastAccess = time(nullptr); - return (cc->loaded || findAny) ? cc : nullptr; - } + CacheNode *cc; + { + mir_cslock lck(cachecs); + cc = arCache.find((CacheNode*)&hContact); + if (cc) { + cc->t_lastAccess = time(nullptr); + return (cc->loaded || findAny) ? cc : nullptr; + } - // not found - if (!add) - return nullptr; + // not found + if (!add) + return nullptr; - cc = new CacheNode(); - cc->hContact = hContact; - arCache.insert(cc); + cc = new CacheNode(); + cc->hContact = hContact; + arCache.insert(cc); + } switch (CreateAvatarInCache(hContact, cc, nullptr)) { case -2: // no avatar data in settings, retrieve -- cgit v1.2.3