RESOLVED FIXED 222634
Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
https://bugs.webkit.org/show_bug.cgi?id=222634
Summary Use adoptNS() right away after calling [obj copy] / [obj mutableCopy]
Chris Dumez
Reported 2021-03-02 16:22:13 PST
Use adoptNS() right away after calling [obj copy] / [obj mutableCopy] to minimize the chance of leaks.
Attachments
Patch (21.56 KB, patch)
2021-03-02 16:29 PST, Chris Dumez
no flags
Patch (21.55 KB, patch)
2021-03-03 13:15 PST, Chris Dumez
no flags
Chris Dumez
Comment 1 2021-03-02 16:29:07 PST
Darin Adler
Comment 2 2021-03-03 13:02:18 PST
Comment on attachment 422020 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422020&action=review > Source/WebCore/platform/cocoa/SystemVersion.mm:40 > - return [[systemVersionInfo objectForKey:@"ProductVersion"] copy]; > + return [systemVersionInfo objectForKey:@"ProductVersion"]; What’s the rationale for moving from copy to retain here? I’m not saying it’s wrong, but we are removing the copy. That means if it happens to be a mutable dictionary we will keep a pointer to it rather than making an immutable copy. I could imagine making the copy in an effort to avoid things being mutated under us or perhaps to optimize memory use since the immutable copy could be smaller. > Source/WebKit/Shared/ApplePay/ApplePayPaymentSetupFeatures.mm:74 > + allowedClasses.get() = WTFMove(allowed); What’s the rationale for moving from copy to retain here? > Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm:93 > + allowedClasses.get() = WTFMove(allowed); What’s the rationale for moving from copy to retain here? > Source/WebKit/Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm:70 > + allowedClasses.get() = WTFMove(allowed); What’s the rationale for moving from copy to retain here? > Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm:110 > - }() copy]; > + }()); What’s the rationale for moving from copy to retain here?
Chris Dumez
Comment 3 2021-03-03 13:03:50 PST
(In reply to Darin Adler from comment #2) > Comment on attachment 422020 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=422020&action=review > > > Source/WebCore/platform/cocoa/SystemVersion.mm:40 > > - return [[systemVersionInfo objectForKey:@"ProductVersion"] copy]; > > + return [systemVersionInfo objectForKey:@"ProductVersion"]; > > What’s the rationale for moving from copy to retain here? > > I’m not saying it’s wrong, but we are removing the copy. That means if it > happens to be a mutable dictionary we will keep a pointer to it rather than > making an immutable copy. I could imagine making the copy in an effort to > avoid things being mutated under us or perhaps to optimize memory use since > the immutable copy could be smaller. I did not realize the benefits of calling [obj copy] here. I will re-introduce those then. > > > Source/WebKit/Shared/ApplePay/ApplePayPaymentSetupFeatures.mm:74 > > + allowedClasses.get() = WTFMove(allowed); > > What’s the rationale for moving from copy to retain here? > > > Source/WebKit/Shared/ApplePay/PaymentSetupConfiguration.mm:93 > > + allowedClasses.get() = WTFMove(allowed); > > What’s the rationale for moving from copy to retain here? > > > Source/WebKit/Shared/ApplePay/cocoa/PaymentSetupConfiguration.mm:70 > > + allowedClasses.get() = WTFMove(allowed); > > What’s the rationale for moving from copy to retain here? > > > Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm:110 > > - }() copy]; > > + }()); > > What’s the rationale for moving from copy to retain here?
Darin Adler
Comment 4 2021-03-03 13:05:52 PST
Comment on attachment 422020 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422020&action=review >>> Source/WebCore/platform/cocoa/SystemVersion.mm:40 >>> + return [systemVersionInfo objectForKey:@"ProductVersion"]; >> >> What’s the rationale for moving from copy to retain here? >> >> I’m not saying it’s wrong, but we are removing the copy. That means if it happens to be a mutable dictionary we will keep a pointer to it rather than making an immutable copy. I could imagine making the copy in an effort to avoid things being mutated under us or perhaps to optimize memory use since the immutable copy could be smaller. > > I did not realize the benefits of calling [obj copy] here. I will re-introduce those then. These are *possible* benefits. Also possible that someone had a choice of typing "retain" or "copy" and selected copy without thinking deeply about tradeoffs.
Chris Dumez
Comment 5 2021-03-03 13:15:57 PST
EWS
Comment 6 2021-03-03 15:07:13 PST
Committed r273848: <https://commits.webkit.org/r273848> All reviewed patches have been landed. Closing bug and clearing flags on attachment 422142 [details].
Radar WebKit Bug Importer
Comment 7 2021-03-03 15:08:16 PST
Note You need to log in before you can comment on or make changes to this bug.