Closed Bug 2092093 Opened 5 days ago Closed 3 days ago

Move the IPCNotification instead of copying it in the DWPNotificationCallbacks constructor

Categories

(Core :: DOM: Push Subscriptions, defect)

defect

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox-esr153 --- unaffected
firefox160 --- wontfix
firefox161 --- wontfix
firefox162 --- fixed

People

(Reporter: Sylvestre, Assigned: ltenenbaum, Mentored)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: good-first-bug, regression, Whiteboard: [lang=c++])

Attachments

(1 external file)

Filing as a good first bug to learn workflows.

Coverity (CID 1701240, COPY_INSTEAD_OF_MOVE) flags the DWPNotificationCallbacks constructor in dom/push/Declarative.cpp. It takes its IPCNotification argument by value and then copies it into the base class:

DWPNotificationCallbacks(const nsAString& aScope, nsIPrincipal* aPrincipal,
                         IPCNotification aNotification)
    : NotificationCallbacksCommon(aScope, aPrincipal, aNotification) {}

NotificationCallbacksCommon also takes IPCNotification by value and moves it into its member, so the copy here is wasted (IPCNotification holds strings and arrays). The fix is to move the parameter, which is not used afterwards:

    : NotificationCallbacksCommon(aScope, aPrincipal,
                                  std::move(aNotification)) {}

Link to the code:
https://searchfox.org/firefox-main/source/dom/push/Declarative.cpp

To verify the fix:

./mach build
./mach test dom/push/test/
./mach format dom/push/Declarative.cpp

Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html

Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.

Set release status flags based on info from the regressing bug 2068765

:ltenenbaum, since you are the author of the regressor, bug 2068765, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(ltenenbaum)

Well the only caller passes it as an rvalue where I expect copy elision, so I don't think a copy is actually happening.

  RefPtr<DWPNotificationCallbacks> dwpCallbacks = new DWPNotificationCallbacks(
      aScope, &aPrincipal, IPCNotification(id, aOptions));

But then I hate C++, these things are too implicit and easy to fire footgun. Rust for DOM when? 🥺

I think it does get copied in the DWPNotificationCallbacks constructor…

Flags: needinfo?(ltenenbaum)
Severity: -- → S3
Assignee: nobody → ltenenbaum
Status: NEW → ASSIGNED
Pushed by ltenenbaum@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/312b0658d4fb https://hg.mozilla.org/integration/autoland/rev/d66b2cb03e0c Move instead of copying IPCNotification in DWPNotificationCallbacks constructor. r=saschanaz
Status: ASSIGNED → RESOLVED
Closed: 3 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: