Skip to content

Commit 1af87bb

Browse files
committed
Fix smart pointers errors with CFRunLoopGetMain()/CFRunLoopGetCurrent()
https://bugs.webkit.org/show_bug.cgi?id=298865 Reviewed by Chris Dumez. Ownership follows the The Get Rule, so they need a RetainPtr: https://developer.apple.com/documentation/corefoundation/cfrunloopgetcurrent()?language=objc https://developer.apple.com/documentation/corefoundation/cfrunloopgetmain()?language=objc * Source/WebKit/SaferCPPExpectations/UnretainedCallArgsCheckerExpectations: * Source/WebKit/UIProcess/WebAuthentication/Cocoa/HidConnection.mm: (WebKit::HidConnection::initialize): (WebKit::HidConnection::terminate): * Source/WebKit/UIProcess/WebAuthentication/Cocoa/HidService.mm: (WebKit::HidService::~HidService): (WebKit::HidService::platformStartDiscovery): * Source/WebKit/UIProcess/mac/WebViewImpl.mm: (WebKit::WebViewImpl::computeHasVisualSearchResults): * Source/WebKit/WebProcess/WebPage/WebDisplayRefreshMonitor.cpp: (WebKit::WebDisplayRefreshMonitor::startNotificationMechanism): * Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm: (WebKit::WebPushToolVerb::done): Canonical link: https://commits.webkit.org/300027@main
1 parent ae5d4eb commit 1af87bb

File tree

6 files changed

+9
-11
lines changed

6 files changed

+9
-11
lines changed

Source/WebKit/SaferCPPExpectations/UnretainedCallArgsCheckerExpectations

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.mm
140140
UIProcess/RemoteLayerTree/mac/RemoteLayerTreeEventDispatcher.mm
141141
UIProcess/WebAuthentication/Cocoa/CcidConnection.mm
142142
UIProcess/WebAuthentication/Cocoa/HidConnection.mm
143-
UIProcess/WebAuthentication/Cocoa/HidService.mm
144143
UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm
145144
UIProcess/WebAuthentication/Cocoa/LocalConnection.mm
146145
UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm
@@ -178,7 +177,6 @@ WebProcess/Plugins/PDF/WKAccessibilityPDFDocumentObject.mm
178177
WebProcess/WebPage/Cocoa/WebPageCocoa.mm
179178
WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm
180179
WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemoteCustom.mm
181-
WebProcess/WebPage/WebDisplayRefreshMonitor.cpp
182180
WebProcess/WebPage/WebPage.cpp
183181
WebProcess/WebPage/mac/PageBannerMac.mm
184182
WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm
@@ -191,4 +189,3 @@ webpushd/WebPushDaemon.mm
191189
webpushd/WebPushDaemonMain.mm
192190
webpushd/_WKMockUserNotificationCenter.mm
193191
webpushd/webpushtool/WebPushToolConnection.mm
194-
webpushd/webpushtool/WebPushToolMain.mm

Source/WebKit/UIProcess/WebAuthentication/Cocoa/HidConnection.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void reportReceived(void* context, IOReturn status, void*, IOHIDReportTyp
7676
{
7777
#if HAVE(SECURITY_KEY_API)
7878
IOHIDDeviceOpen(m_device.get(), kIOHIDOptionsTypeSeizeDevice);
79-
IOHIDDeviceScheduleWithRunLoop(m_device.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
79+
IOHIDDeviceScheduleWithRunLoop(m_device.get(), retainPtr(CFRunLoopGetCurrent()).get(), kCFRunLoopDefaultMode);
8080
m_inputBuffer.resize(kHidMaxPacketSize);
8181
IOHIDDeviceRegisterInputReportCallback(m_device.get(), m_inputBuffer.mutableSpan().data(), m_inputBuffer.size(), &reportReceived, this);
8282
#endif
@@ -87,7 +87,7 @@ static void reportReceived(void* context, IOReturn status, void*, IOHIDReportTyp
8787
{
8888
#if HAVE(SECURITY_KEY_API)
8989
IOHIDDeviceRegisterInputReportCallback(m_device.get(), m_inputBuffer.mutableSpan().data(), m_inputBuffer.size(), nullptr, nullptr);
90-
IOHIDDeviceUnscheduleFromRunLoop(m_device.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
90+
IOHIDDeviceUnscheduleFromRunLoop(m_device.get(), retainPtr(CFRunLoopGetCurrent()).get(), kCFRunLoopDefaultMode);
9191
IOHIDDeviceClose(m_device.get(), kIOHIDOptionsTypeNone);
9292
#endif
9393
m_isInitialized = false;

Source/WebKit/UIProcess/WebAuthentication/Cocoa/HidService.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void deviceRemovedCallback(void* context, IOReturn, void*, IOHIDDeviceRef
7373
HidService::~HidService()
7474
{
7575
#if HAVE(SECURITY_KEY_API)
76-
IOHIDManagerUnscheduleFromRunLoop(m_manager.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
76+
IOHIDManagerUnscheduleFromRunLoop(m_manager.get(), retainPtr(CFRunLoopGetCurrent()).get(), kCFRunLoopDefaultMode);
7777
IOHIDManagerClose(m_manager.get(), kIOHIDOptionsTypeNone);
7878
#endif
7979
}
@@ -86,7 +86,7 @@ static void deviceRemovedCallback(void* context, IOReturn, void*, IOHIDDeviceRef
8686
void HidService::platformStartDiscovery()
8787
{
8888
#if HAVE(SECURITY_KEY_API)
89-
IOHIDManagerScheduleWithRunLoop(m_manager.get(), CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
89+
IOHIDManagerScheduleWithRunLoop(m_manager.get(), retainPtr(CFRunLoopGetCurrent()).get(), kCFRunLoopDefaultMode);
9090
IOHIDManagerOpen(m_manager.get(), kIOHIDOptionsTypeNone);
9191
#endif
9292
}

Source/WebKit/UIProcess/mac/WebViewImpl.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6976,11 +6976,12 @@ static NSTextAlignment nsTextAlignmentFromTextAlignment(TextAlignment textAlignm
69766976
auto startTime = MonotonicTime::now();
69776977
[ensureImageAnalyzer() processRequest:request.get() progressHandler:nil completionHandler:makeBlockPtr([completion = WTFMove(completion), startTime] (CocoaImageAnalysis *analysis, NSError *) mutable {
69786978
BOOL result = [analysis hasResultsForAnalysisTypes:VKAnalysisTypeVisualSearch];
6979-
CFRunLoopPerformBlock(CFRunLoopGetMain(), (__bridge CFStringRef)NSEventTrackingRunLoopMode, makeBlockPtr([completion = WTFMove(completion), result, startTime] () mutable {
6979+
RetainPtr loop = CFRunLoopGetMain();
6980+
CFRunLoopPerformBlock(loop.get(), (__bridge CFStringRef)NSEventTrackingRunLoopMode, makeBlockPtr([completion = WTFMove(completion), result, startTime] () mutable {
69806981
RELEASE_LOG(ImageAnalysis, "Image analysis completed in %.0f ms (found visual search results? %d)", (MonotonicTime::now() - startTime).milliseconds(), result);
69816982
completion(result);
69826983
}).get());
6983-
CFRunLoopWakeUp(CFRunLoopGetMain());
6984+
CFRunLoopWakeUp(loop.get());
69846985
}).get()];
69856986
}
69866987

Source/WebKit/WebProcess/WebPage/WebDisplayRefreshMonitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool WebDisplayRefreshMonitor::startNotificationMechanism()
9393
});
9494
}
9595

96-
m_runLoopObserver->schedule(CFRunLoopGetCurrent());
96+
m_runLoopObserver->schedule(retainPtr(CFRunLoopGetCurrent()).get());
9797
#endif
9898
m_displayLinkIsActive = true;
9999

Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static bool registerDaemonWithLaunchD(WebPushTool::PreferTestService preferTestS
172172
public:
173173
virtual ~WebPushToolVerb() = default;
174174
virtual void run(WebPushTool::Connection&) = 0;
175-
virtual void done() { CFRunLoopStop(CFRunLoopGetMain()); }
175+
virtual void done() { CFRunLoopStop(retainPtr(CFRunLoopGetMain()).get()); }
176176
};
177177

178178
class InjectPushMessageVerb : public WebPushToolVerb {

0 commit comments

Comments
 (0)