Closed Bug 323454 Opened 19 years ago Closed 19 years ago

[FIX]Don't leak the channel and XMLHttpRequest object if AsyncOpen fails

Categories

(Core :: DOM: Core & HTML, defect, P3)

defect

Tracking

()

VERIFIED FIXED
mozilla1.9alpha1

People

(Reporter: martijn.martijn, Assigned: bzbarsky)

References

()

Details

(Keywords: fixed1.8.1, memory-leak, testcase)

Attachments

(2 files)

When visiting the url, Mozilla leaks memory: Summary: Leaked 2 out of 10 DOM Windows Leaked 3 out of 36 documents Leaked 0 out of 4 docshells I'll attach a testcase from that site that leaks 2 DOM Windows in Mozilla.
Attached file testcase
Related to bug 206520? (XMLHttpRequest related)
Maybe, except in this testcase, send is called and no event listener is set.
Apparently, the testcase only leaks when testing locally.
So the problem here is that OpenContentStream() throws for a nonexistent file:// URI in nsBaseChannel::AsyncOpen. And then we leak because the XMLHttpRequest has the channel in mChannel and the channel has a ref to XMLHttpRequest via the notification callbacks. Should nsBaseChannel::AsyncOpen drop notification callbacks on any failure? Or should XMLHttpRequest null out mChannel? Or both, perhaps? Note that this issue is specific to file:// URIs, so the MSN money thing is likely a different issue...
this would, obviously, be fixed if nonexistant file uris didn't throw in asyncopen, right? I don't think AsyncOpen should drop notificationCallbacks in this case. maybe xmlhttprequest should set them to null explicitly.
> this would, obviously, be fixed if nonexistant file uris didn't throw in > asyncopen, right? True, but I was wondering about the general behavior (eg if allocating an nsInputStreamPump is OOM). Is doing anything with a channel after AsyncOpen() fails supported?
Any caller of nsIChannel::AsyncOpen needs to be prepared for it to fail. The particulars of why it fails here aren't really relevant. XMLHttpRequest should ensure that if AsyncOpen fails that it breaks any reference cycles it may have created. I vote for having XMLHttpRequest clear the channel's notification callbacks in this error case.
Actually, I was thinking it should just drop the mChannel ref if the AsyncOpen fails. That said, we should probably check on other AsyncOpen callers and see whether they suffer from similar problems...
Agreed. Docshell avoids this by hooking up a weakref to itself as the notification callbacks for channels it creates.
Attached patch Proposed fixSplinter Review
I skimmed the other AsyncOpen callers and they look ok to me.
Assignee: general → bzbarsky
Status: NEW → ASSIGNED
Attachment #212190 - Flags: superreview?(darin)
Attachment #212190 - Flags: review?(cbiesinger)
OS: Windows XP → All
Priority: -- → P3
Hardware: PC → All
Summary: Memory leak when visiting MSN Money → [FIX]Memory leak when visiting MSN Money
Target Milestone: --- → mozilla1.9alpha
Comment on attachment 212190 [details] [diff] [review] Proposed fix ok, but chrome apps can access .channel. will they be confused to see the channel go away?
Attachment #212190 - Flags: superreview?(darin) → superreview+
Not sure... But they shouldn't be accessing it anyway after a failed AsyncOpen, since it's in an indeterminate state. Since they have no way to tell that, I think this is better than letting them mess with the channel at that point... I would be happy to document that on the interface.
Thanks for that fix, Boris. As soon as that fix gets checked in, I'll try to get a minimised testcase again (it's currently confusing to get different memory leaks when you test it locally).
Attachment #212190 - Flags: review?(cbiesinger) → review+
Fixed on trunk.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Comment on attachment 212190 [details] [diff] [review] Proposed fix I think it's worth taking this on the branch.
Attachment #212190 - Flags: approval-branch-1.8.1?(darin)
Summary: [FIX]Memory leak when visiting MSN Money → [FIX]Don't leak the channel and XMLHttpRequest object if AsyncOpen fails
Attachment #212190 - Flags: approval-branch-1.8.1?(darin) → approval-branch-1.8.1+
Fixed on 1.8 branch.
Keywords: fixed1.8.1
Verified fixed, using 2006-02-22 trunk build. I still leak with the url as Boris already expected. I filed bug 328311 for it. (hoping I can make a minimal testcase of that).
Status: RESOLVED → VERIFIED
Depends on: 366467
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: