Per documentation, -[NSData dataWithBytesNoCopy:length:] takes ownership of malloc()-ed memory, then frees it when it's released. These tests were passing global variables into the method, which is not malloc()-ed memory, which violations the API contract. The fix is to switch to using -[NSData dataWithBytes:length:] so that the global C strings are copied into malloc()-ed memory. Caught by the clang static analyzer.
Created attachment 313579 [details] Patch v1
Comment on attachment 313579 [details] Patch v1 View in context: https://bugs.webkit.org/attachment.cgi?id=313579&action=review > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm:-145 > - RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes)]]); Why not keep the existing code but add "freeWhenDone:NO" ? https://developer.apple.com/documentation/foundation/nsdata/1416020-initwithbytesnocopy?language=objc
(In reply to Chris Dumez from comment #2) > Comment on attachment 313579 [details] > Patch v1 > > View in context: > https://bugs.webkit.org/attachment.cgi?id=313579&action=review > > > Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm:-145 > > - RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes)]]); > > Why not keep the existing code but add "freeWhenDone:NO" ? > https://developer.apple.com/documentation/foundation/nsdata/1416020- > initwithbytesnocopy?language=objc Sure, could do that as well. I saw the shorter method first!
Created attachment 313586 [details] Patch v2
Committed r218694: <http://trac.webkit.org/changeset/218694>