Closed Bug 892448 Opened 11 years ago Closed 11 years ago

Wrong ref counting in CompositableHost::Create

Categories

(Core :: Graphics: Layers, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: nical, Assigned: nical)

Details

Attachments

(1 file, 2 obsolete files)

Attached patch Fix the ref counting problem (obsolete) — Splinter Review
ew, I am surprised we haven't seen that earlier. (or do we have some implicit magic when casting a RefPtr into a TemporaryRef? in any case I much prefer having return result.forget() explicitly)
Attachment #773908 - Flags: review?(bgirard)
Assignee: nobody → nical.bugzilla
Attached patch Fix the ref counting problem (obsolete) — Splinter Review
oops, better fix
Attachment #773908 - Attachment is obsolete: true
Attachment #773908 - Flags: review?(bgirard)
Attachment #773913 - Flags: review?(bgirard)
darn, uploaded the wrong file again, sorry for the mail churn
Attachment #773913 - Attachment is obsolete: true
Attachment #773913 - Flags: review?(bgirard)
Attachment #773915 - Flags: review?(bgirard)
Comment on attachment 773915 [details] [diff] [review]
Fix the ref counting problem

Can you verify if this is actually a problem? This is useful to know because:
- We should uplift this patch
- I'm seeing a large number of TiledContentHost in a different bug
- If it is a bug then we could add a runtime debug check for this kind of pattern.
(In reply to Benoit Girard (:BenWa) from comment #3)
> Comment on attachment 773915 [details] [diff] [review]
> Fix the ref counting problem
> 
> Can you verify if this is actually a problem? This is useful to know because:
> - We should uplift this patch
> - I'm seeing a large number of TiledContentHost in a different bug
> - If it is a bug then we could add a runtime debug check for this kind of
> pattern.

Actually it is not a problem with RefPtr. Unlike alread_AddRefed, TemporaryRef(T*) increments the refcount ( http://dxr.mozilla.org/mozilla-central/source/mfbt/RefPtr.h#l221 ), and RefPtr has the operator TemporaryRef ( http://dxr.mozilla.org/mozilla-central/source/mfbt/RefPtr.h#l184 ) which calls the right constructor in TemporaryRef that does the increment.
So when RefPtr goes out of scope the ref count is 2 and things are good.

So false alert, I assumed that TemporaryRef behaved like already_AdRefed which isn't as smart.

I don't know whether we still want to impose the return result.forget() style to avoid mistakes with nsRefPtr or not, but this patch turns out to just be cosmetic.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
Comment on attachment 773915 [details] [diff] [review]
Fix the ref counting problem

Taking off review since the bug is closed.
Attachment #773915 - Flags: review?(bgirard)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: