12012-06-11 Xianzhu Wang <wangxianzhu@chromium.org>
2
3 SVGImageCache leaks image data
4 https://bugs.webkit.org/show_bug.cgi?id=87792
5
6 There are two functions to remove a client from a CachedImage:
7 - CachedResource::removeClient()
8 - CachedImage::removeClientForRenderer().
9 It's easy to make error to call the former which will leak the cached
10 image buffers in SVGImageCache.
11
12 This change combined the two by adding the virtual
13 CachedResource::didRemoveClient(). CachedImage will do SVGImageCache
14 cleanup in the function.
15
16 Reviewed by Nikolas Zimmermann.
17
18 Test: svg/as-image/svg-image-leak-cached-data.html
19
20 * loader/cache/CachedFont.h:
21 (WebCore::CachedFontClient::resourceClientType): Added 'const'.
22 * loader/cache/CachedImage.cpp:
23 (WebCore):
24 (WebCore::CachedImage::didRemoveClient): Removes the client from SVGImageCache.
25 (WebCore::CachedImage::lookupOrCreateImageForRenderer):
26 * loader/cache/CachedImage.h:
27 (CachedImage):
28 (WebCore::CachedImageClient::resourceClientType): Added 'const'.
29 * loader/cache/CachedRawResource.h:
30 (WebCore::CachedRawResourceClient::resourceClientType): Added 'const'.
31 * loader/cache/CachedResource.cpp:
32 (WebCore::CachedResource::removeClient): Added invocation of didRemoveClient().
33 * loader/cache/CachedResource.h:
34 (WebCore::CachedResource::didRemoveClient): Added for subclasses to do additional works.
35 * loader/cache/CachedResourceClient.h:
36 (WebCore::CachedResourceClient::resourceClientType): Added 'const'.
37 * loader/cache/CachedSVGDocument.h:
38 (WebCore::CachedSVGDocumentClient::resourceClientType): Added 'const'.
39 * loader/cache/CachedStyleSheetClient.h:
40 (WebCore::CachedStyleSheetClient::resourceClientType): Added 'const'.
41 * rendering/style/StyleCachedImage.cpp:
42 (WebCore::StyleCachedImage::removeClient):
43 * rendering/style/StyleCachedImageSet.cpp:
44 (WebCore::StyleCachedImageSet::removeClient):
45 * svg/graphics/SVGImageCache.cpp:
46 (WebCore::SVGImageCache::~SVGImageCache): Added checking for leaks.
47 (WebCore::SVGImageCache::removeClientFromCache):
48 (WebCore::SVGImageCache::setRequestedSizeAndScales):
49 (WebCore::SVGImageCache::requestedSizeAndScales):
50 (WebCore::SVGImageCache::lookupOrCreateBitmapImageForClient):
51 * svg/graphics/SVGImageCache.h:
52 (WebCore):
53 (SVGImageCache):
54