From 0204a7873309bd43d22ef3cf5f6b55a401a518d4 Mon Sep 17 00:00:00 2001 From: "zverre@yandex-team.ru" Date: Thu, 24 Oct 2013 03:18:59 +0000 Subject: Fixed memory leak in icon_manager When there is an entry in the cache and the |result| is NULL we put NULL in the cache without deleting current entry. Also I offer to simplify logic and to dissalow NULLs to reside in the cache. This does not affect any current code. BUG= Review URL: https://codereview.chromium.org/27529002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230614 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/icon_manager.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'chrome/browser/icon_manager.cc') diff --git a/chrome/browser/icon_manager.cc b/chrome/browser/icon_manager.cc index 6c7f9fc..d0e2cbc 100644 --- a/chrome/browser/icon_manager.cc +++ b/chrome/browser/icon_manager.cc @@ -107,17 +107,21 @@ bool IconManager::OnImageLoaded( const ClientRequest& client_request = rit->second; - // Cache the bitmap. Watch out: |result| or the cached bitmap may be NULL to - // indicate a current or past failure. + // Cache the bitmap. Watch out: |result| may be NULL to indicate a current + // failure. We assume that if we have an entry in |icon_cache_| + // it must not be NULL. CacheKey key(group, client_request.size); IconMap::iterator it = icon_cache_.find(key); - if (it != icon_cache_.end() && result && it->second) { - if (it->second != result) { + if (it != icon_cache_.end()) { + if (!result) { + delete it->second; + icon_cache_.erase(it); + } else if (result != it->second) { it->second->SwapRepresentations(result); delete result; result = it->second; } - } else { + } else if (result) { icon_cache_[key] = result; } -- cgit v1.1