Bug Summary

File:Source/WebKitLegacy/mac/Misc/WebCache.mm
Warning:line 168, column 11
Local variable 'cachedImage' is uncounted and unsafe

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple arm64-apple-ios26.2.0-simulator -O3 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name WebCache.mm -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=osx -analyzer-checker=security.insecureAPI.decodeValueOfObjCType -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -target-sdk-version=26.2 -fdepfile-entry=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/SDKSettings.json -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fno-modulemap-allow-subdirectory-search -fdefine-target-os-macros -enable-tlsdesc -target-cpu apple-m1 -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -target-abi darwinpcs -dwarf-ext-refs -fmodule-format=obj -debug-info-kind=standalone -dwarf-version=5 -debugger-tuning=lldb -fdebug-compilation-dir=/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebKitLegacy -target-linker-version 1230.1 -fcoverage-compilation-dir=/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebKitLegacy -resource-dir /Users/buildbot/Library/Developer/Toolchains/swift-webkit.xctoolchain/usr/lib/clang/21 -dependency-file /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/scan-build-output/StaticAnalyzer/WebKitLegacy/WebKitLegacy/normal/arm64/WebCache.d -skip-unused-modulemap-deps -MT dependencies -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk -iquote /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/WebKitLegacy-generated-files.hmap -iquote /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/WebKitLegacy-project-headers.hmap -isystem /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitLibraries/SDKs/iphonesimulator26.0-additions.sdk/usr/local/include -isystem /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/SDKAdditions/usr/include -iframework /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/SDKAdditions/System/Library/Frameworks -iframework /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitLibraries/SDKs/iphonesimulator26.0-additions.sdk/System/Library/PrivateFrameworks -iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/System/Library/Frameworks -isystem /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitLibraries/SDKs/iphonesimulator26.0-additions.sdk/usr/local/include -include-pch /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/PrecompiledHeaders/SharedPrecompiledHeaders/4881137874571366320/WebKitPrefix.h.gch -D _LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D NDEBUG -D ENABLE_WEBKIT_UNSET_DYLD_FRAMEWORK_PATH -D BUILDING_WEBKIT -D FRAMEWORK_NAME=WebKitLegacy -D OBJC_OLD_DISPATCH_PROTOTYPES=0 -D __clang_analyzer__ -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/WebKitLegacy-own-target-headers.hmap -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/WebKitLegacy-all-target-headers.hmap -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/include -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/WebCore.framework/PrivateHeaders/ForwardingHeaders -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/DerivedSources/WebKitLegacy -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/pal/graphics/WebGPU -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/pal/graphics/WebGPU -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/WebKitAdditions -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/WebKitAdditions -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/webrtc -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/webrtc -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator/usr/local/include/webm -I /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include/webm -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebKitLegacy -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/DerivedSources-normal/arm64 -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/DerivedSources/arm64 -I /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/WebKitLegacy.build/Release-iphonesimulator/WebKitLegacy.build/DerivedSources -F/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator -F/Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/WebKitBuild/Release-iphonesimulator -D ENABLE_BUILD_FOR_TESTING -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/local/include -internal-isystem /Users/buildbot/Library/Developer/Toolchains/swift-webkit.xctoolchain/usr/lib/clang/21/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/usr/include -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/System/Library/Frameworks -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/System/Library/SubFrameworks -internal-iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator26.2.sdk/Library/Frameworks -Wno-trigraphs -Werror -Wno-missing-field-initializers -Wmissing-prototypes -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Wno-objc-interface-ivars -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wnon-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wsign-compare -Wno-shorten-64-to-32 -Wnewline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -Wno-c++11-extensions -Wno-implicit-fallthrough -Wprotocol -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wno-semicolon-before-method-body -Wall -Wc99-designator -Wconditional-uninitialized -Wextra -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion -Wenum-float-conversion -Wfinal-dtor-non-final-class -Wformat=2 -Wmisleading-indentation -Wpointer-to-int-cast -Wreorder-init-list -Wundef -Wunused-but-set-variable -Wvla -Werror=unguarded-availability -Wno-elaborated-enum-base -Wno-unused-parameter -Wcast-qual -Wchar-subscripts -Wextra-tokens -Winit-self -Wmissing-noreturn -Wpacked -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wexit-time-destructors -Wglobal-constructors -Wtautological-compare -Wimplicit-fallthrough -Wvla -Wliteral-conversion -Wthread-safety -std=c++2b -fdeprecated-macro -ferror-limit 19 -fmacro-backtrace-limit=0 -fvisibility-inlines-hidden -stack-protector 1 -fblocks -fencode-extended-block-signature -fno-rtti -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fobjc-runtime=ios-26.2.0 -fobjc-weak -fobjc-exceptions -fexceptions -fpascal-strings -fmax-type-align=16 -fdiagnostics-show-note-include-stack -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config report-in-main-source-file=true -analyzer-config nullability:NoDiagnoseCallsToSystemHeaders=true -analyzer-checker optin.osx.cocoa.localizability.NonLocalizedStringChecker -analyzer-checker security.insecureAPI.UncheckedReturn -analyzer-checker security.insecureAPI.getpw -analyzer-checker security.insecureAPI.gets -analyzer-checker security.insecureAPI.mkstemp -analyzer-checker security.insecureAPI.mktemp -analyzer-disable-checker security.insecureAPI.rand -analyzer-disable-checker security.insecureAPI.strcpy -analyzer-checker security.insecureAPI.vfork -analyzer-disable-checker alpha,apiModeling,core,cplusplus,deadcode,debug,fuchsia,nullability,optin,osx,security,unix,webkit -analyzer-checker alpha.webkit.ForwardDeclChecker,alpha.webkit.MemoryUnsafeCastChecker,alpha.webkit.NoDeleteChecker,alpha.webkit.NoUncheckedPtrMemberChecker,alpha.webkit.NoUnretainedMemberChecker,alpha.webkit.RetainPtrCtorAdoptChecker,alpha.webkit.UncheckedCallArgsChecker,alpha.webkit.UncheckedLocalVarsChecker,alpha.webkit.UncountedCallArgsChecker,alpha.webkit.UncountedLocalVarsChecker,alpha.webkit.UnretainedCallArgsChecker,alpha.webkit.UnretainedLambdaCapturesChecker,alpha.webkit.UnretainedLocalVarsChecker,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor,webkit.UncountedLambdaCapturesChecker -analyzer-config max-nodes=10000000 -analyzer-config verbose-report-filename=true -fdwarf2-cfi-asm -o /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/scan-build-output/StaticAnalyzer/WebKitLegacy/WebKitLegacy/normal/arm64/WebCache.plist -x objective-c++ /Volumes/Data/worker/Apple-iOS-26-Safer-CPP-Checks-EWS/build/Source/WebKitLegacy/mac/Misc/WebCache.mm
1/*
2 * Copyright (C) 2006 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#import "WebCache.h"
27
28#import "NetworkStorageSessionMap.h"
29#import "WebNSObjectExtras.h"
30#import "WebPreferences.h"
31#import "WebView.h"
32#import "WebViewInternal.h"
33#import <JavaScriptCore/InitializeThreading.h>
34#import <WebCore/CookieJar.h>
35#import <WebCore/CredentialStorage.h>
36#import <WebCore/CrossOriginPreflightResultCache.h>
37#import <WebCore/Document.h>
38#import <WebCore/MemoryCache.h>
39#import <WebCore/NativeImage.h>
40#import <WebCore/NetworkStorageSession.h>
41#import <WebCore/StorageSessionProvider.h>
42#import <WebCore/WebCoreJITOperations.h>
43#import <WebCore/WebCoreMainThread.h>
44#import <wtf/MainThread.h>
45#import <wtf/RunLoop.h>
46
47#if PLATFORM(IOS_FAMILY)(defined 1 && 1)
48#import "WebFrameInternal.h"
49#import <WebCore/BackForwardCache.h>
50#import <WebCore/CachedImage.h>
51#import <WebCore/LocalFrame.h>
52#import <WebCore/WebCoreThreadRun.h>
53#endif
54
55class DefaultStorageSessionProvider : public WebCore::StorageSessionProvider {
56 WebCore::NetworkStorageSession* storageSession() const final
57 {
58 return &NetworkStorageSessionMap::defaultStorageSession();
59 }
60};
61
62@implementation WebCache
63
64+ (void)initialize
65{
66 WebCore::initializeMainThreadIfNeeded();
67}
68
69+ (NSArray *)statistics
70{
71 auto s = WebCore::MemoryCache::singleton().getStatistics();
72 return @[
73 @{
74 @"Images": @(s.images.count),
75 @"CSS": @(s.cssStyleSheets.count),
76#if ENABLE(XSLT)(defined 1 && 1)
77 @"XSL": @(s.xslStyleSheets.count),
78#else
79 @"XSL": @(0),
80#endif
81 @"JavaScript": @(s.scripts.count),
82 },
83 @{
84 @"Images": @(s.images.size),
85 @"CSS": @(s.cssStyleSheets.size),
86#if ENABLE(XSLT)(defined 1 && 1)
87 @"XSL": @(s.xslStyleSheets.size),
88#else
89 @"XSL": @(0),
90#endif
91 @"JavaScript": @(s.scripts.size),
92 },
93 @{
94 @"Images": @(s.images.liveSize),
95 @"CSS": @(s.cssStyleSheets.liveSize),
96#if ENABLE(XSLT)(defined 1 && 1)
97 @"XSL": @(s.xslStyleSheets.liveSize),
98#else
99 @"XSL": @(0),
100#endif
101 @"JavaScript": @(s.scripts.liveSize),
102 },
103 @{
104 @"Images": @(s.images.decodedSize),
105 @"CSS": @(s.cssStyleSheets.decodedSize),
106#if ENABLE(XSLT)(defined 1 && 1)
107 @"XSL": @(s.xslStyleSheets.decodedSize),
108#else
109 @"XSL": @(0),
110#endif
111 @"JavaScript": @(s.scripts.decodedSize),
112 },
113 ];
114}
115
116+ (void)empty
117{
118 // Toggling the cache model like this forces the cache to evict all its in-memory resources.
119 WebCacheModel cacheModel = [WebView _cacheModel];
120 [WebView _setCacheModel:WebCacheModelDocumentViewer];
121 [WebView _setCacheModel:cacheModel];
122
123 // Empty the Cross-Origin Preflight cache
124 WebCore::CrossOriginPreflightResultCache::singleton().clear();
125}
126
127#if PLATFORM(IOS_FAMILY)(defined 1 && 1)
128
129+ (void)emptyInMemoryResources
130{
131 // This method gets called from MobileSafari after it calls [WebView
132 // _close]. [WebView _close] schedules its work on the WebThread. So we
133 // schedule this method on the WebThread as well so as to pick up all the
134 // dead resources left behind after closing the WebViews
135 WebThreadRun(^{
136 // Toggling the cache model like this forces the cache to evict all its in-memory resources.
137 WebCacheModel cacheModel = [WebView _cacheModel];
138 [WebView _setCacheModel:WebCacheModelDocumentViewer];
139 [WebView _setCacheModel:cacheModel];
140
141 WebCore::MemoryCache::singleton().pruneLiveResources(true);
142 });
143}
144
145+ (void)sizeOfDeadResources:(int *)resources
146{
147 WebCore::MemoryCache::Statistics stats = WebCore::MemoryCache::singleton().getStatistics();
148 if (resources) {
149 *resources = (stats.images.size - stats.images.liveSize)
150 + (stats.cssStyleSheets.size - stats.cssStyleSheets.liveSize)
151#if ENABLE(XSLT)(defined 1 && 1)
152 + (stats.xslStyleSheets.size - stats.xslStyleSheets.liveSize)
153#endif
154 + (stats.scripts.size - stats.scripts.liveSize);
155 }
156}
157
158+ (CGImageRef)imageForURL:(NSURL *)url
159{
160 if (!url)
161 return nullptr;
162
163 WebCore::ResourceRequest request(url);
164 WebCore::CachedResource* cachedResource = WebCore::MemoryCache::singleton().resourceForRequest(request, PAL::SessionID::defaultSessionID());
165 if (!is<WebCore::CachedImage>(cachedResource))
166 return nullptr;
167
168 auto& cachedImage = downcast<WebCore::CachedImage>(*cachedResource);
Local variable 'cachedImage' is uncounted and unsafe
169 if (!cachedImage.hasImage())
170 return nullptr;
171
172 auto nativeImage = cachedImage.image()->nativeImage();
173 if (!nativeImage)
174 return nullptr;
175
176 return nativeImage->platformImage().get();
177}
178
179#endif // PLATFORM(IOS_FAMILY)
180
181+ (void)setDisabled:(BOOL)disabled
182{
183 if (!pthread_main_np())
184 return [[self _webkit_invokeOnMainThread] setDisabled:disabled];
185
186 WebCore::MemoryCache::singleton().setDisabled(disabled);
187}
188
189+ (BOOL)isDisabled
190{
191 return WebCore::MemoryCache::singleton().disabled();
192}
193
194+ (void)clearCachedCredentials
195{
196 [WebView _makeAllWebViewsPerformSelector:@selector(_clearCredentials)];
197 NetworkStorageSessionMap::defaultStorageSession().credentialStorage().clearCredentials();
198}
199
200@end