Closed Bug 1665026 Opened 5 years ago Closed 5 years ago

Prevent ToResultInvoke from being instantiated with a raw pointer result type

Categories

(Core :: MFBT, task)

task

Tracking

()

RESOLVED FIXED
82 Branch
Tracking Status
firefox82 --- fixed

People

(Reporter: sg, Assigned: sg)

Details

Attachments

(1 file)

The following would produce a leak, since the result type with be Result<nsIFile*, nsresult>:

bool DoIt(nsIFile& aFile) {
  auto res = ToResultInvoke(std::mem_fn(&nsIFIle::Clone), aFile);
  return res.isOk();
}

The correct way to do this would be to specify explicitly that a smart pointer should be the result type:

void DoIt(nsIFile& aFile) {
  auto res = ToResultInvoke<nsCOMPtr<nsIFile>>(std::mem_fn(&nsIFIle::Clone), aFile);
  return res.isOk();
}

The former variant should therefore be prevented from being instantiated.

Note that this also prevents ToResultInvoke to be used with non-owning raw pointer output parameters, but XPCOM conventions do not allow this, at least not for ref-counted types.

Summary: Prevent ToResultInvoke to be instantiated with a raw pointer result type → Prevent ToResultInvoke from being instantiated with a raw pointer result type
Pushed by sgiesecke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/dd6db9d9349c Prevent ToResultInvoke from being instantiated with a raw pointer result type. r=janv
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: