Closed Bug 814470 Opened 13 years ago Closed 13 years ago

AsyncFetchAndSetIconFromNetwork may leak channel when setup fails

Categories

(Toolkit :: Places, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla20
Tracking Status
firefox19 --- fixed
firefox20 --- fixed
b2g18 --- fixed

People

(Reporter: nmaier, Assigned: nmaier)

References

Details

Attachments

(1 file, 2 obsolete files)

The AsyncFetchAndSetIconFromNetwork helper tracks the associated channel in the mChannel member. In ::Run, the channel setup may fail in such a way that a leak is created, e.g. when the nsIChannel::AsyncOpen fails, as the channel references AFASIFN and vice versa, creating circular references. This blocks bug 719180, which changes the jar channel implementation so that ::AsyncOpen there will fail early in some cases (instead of failing in OnStopRequest later). Please note that even without said changes ::AsyncOpen may fail causing a leak in this helper.
Do not track the channel in the first place, thus avoiding a circular references Marco, since you seem to have written the original code, can you please review?
Assignee: nobody → MaierMan
Status: NEW → ASSIGNED
Attachment #684460 - Flags: review?(mak77)
Green try: https://tbpl.mozilla.org/?tree=Try&rev=d823eea1abc0 The patch does not depend on the bug 719180 patches on top.
Does AsyncOpen ensure the channel stays alive by itself until done? Otherwise, would it be fine to just null mChannel if AsyncOpen fails? Regarding the change to AsyncFetchAndSetIconFromNetwork::OnStopRequest, in which case we we may reach that point with a success status code, but unable to QI the request to nsIChannel? Note that in any case GetExpirationTimeFromChannel should be capable to handle invalid argument by itself, at a maximum we may add an abort to ensure doesn't happen. Regardless all of this, please try to keep changes to a minimum, there's no need to do all of that "cleanup" (like the NS_ENSURE_SUCCESS replacements, or moving nsresult) just to fix this bug.
(In reply to Marco Bonardo [:mak] from comment #3) > Does AsyncOpen ensure the channel stays alive by itself until done? AFAIK, yes. As long as AsyncOpen succeeded, something will always strong-ref the channel until OnStopRequest. > Regarding the change to AsyncFetchAndSetIconFromNetwork::OnStopRequest, in > which case we we may reach that point with a success status code, but unable > to QI the request to nsIChannel? This should always QI to nsIChannel, yes. MOZ_ASSERT would work as well to make sure of that.
Comment on attachment 684460 [details] [diff] [review] Fix a leak when channel setup in AsyncFetchAndSetIconFromNetwork fails Review of attachment 684460 [details] [diff] [review]: ----------------------------------------------------------------- Ok, so I'd just like to get a minimal patch without code polish
Attachment #684460 - Flags: review?(mak77)
Comments addressed
Attachment #684460 - Attachment is obsolete: true
Attachment #685287 - Flags: review?(mak77)
Comment on attachment 685287 [details] [diff] [review] Bug 814470: Fix a leak when channel setup in AsyncFetchAndSetIconFromNetwork fails Review of attachment 685287 [details] [diff] [review]: ----------------------------------------------------------------- It looks good, thank you. ::: toolkit/components/places/AsyncFaviconHelpers.cpp @@ +565,5 @@ > nsCOMPtr<nsIURI> iconURI; > nsresult rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec); > NS_ENSURE_SUCCESS(rv, rv); > + > + nsCOMPtr<nsIChannel> channel; nit: the added empty like doesn't look needed here
Attachment #685287 - Flags: review?(mak77) → review+
Same patch, sans that newline. Green try: https://tbpl.mozilla.org/?tree=Try&rev=240962f65a48
Keywords: checkin-needed
Attachment #685287 - Attachment is obsolete: true
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla20
Attachment #685574 - Flags: approval-mozilla-b2g18?
Attachment #685574 - Flags: approval-mozilla-aurora?
Attachment #685574 - Flags: approval-mozilla-b2g18?
Attachment #685574 - Flags: approval-mozilla-b2g18+
Attachment #685574 - Flags: approval-mozilla-aurora?
Attachment #685574 - Flags: approval-mozilla-aurora+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: