Closed Bug 371374 Opened 18 years ago Closed 18 years ago

Memory leaks (potentially severe) when Event Queues are pushed and popped

Categories

(Core :: XPCOM, defect)

defect
Not set
critical

Tracking

()

RESOLVED FIXED

People

(Reporter: bas.schouten, Assigned: bas.schouten)

References

Details

(Keywords: memory-leak)

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Build Identifier: 

When two threads communicate through an asynchronous proxy call they push additional event queues on the thread, and use those. Once they are done with these they are popped but the actual nsEventQueue object is not deleted, the lock and pages belonging to the event therefore linger in memory. Furthermore event pages are not properly freed. In my case I'm seeing this leak cause memory usage increase by 5 MB/s, going up until the program crashes.

Reproducible: Always
Keywords: mlk
Attached patch Patch (deleted) — Splinter Review
Assignee: nobody → bas.schouten
Oh, good catch!

Deleting the page shouldn't really be needed because the caller should have gotten all the events from the queue first, which would delete the page, no?.  But it seems like the safe thing to do.  We should also perhaps consider releasing whatever events are left in the queue, if any.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: blocking1.9?
      if (mOffsetHead == EVENTS_PER_PAGE) {
        Page *dead = mHead;
        mHead = mHead->mNext;
        FreePage(dead);
        mOffsetHead = 0;
      }
Take a note of this particular part of code, see how the logic is flawed? The page only gets deleted if the pointer reaches the end of it... you could alter this by adding logic here like:
if (mOffsetHead == EVENTS_PER_PAGE || (mHead == mTail && mOffsetHead = mOffsetTail))

But this would mean you're deallocating every time the queue is processed and re-allocating every time it gets an event, it's far more efficient to delete the page upon destruction.. as far as I can see that is :)
Comment on attachment 256164 [details] [diff] [review]
Patch

Bas, you want to request module owner review on patches.  ;)

And good point on the page thing!
Attachment #256164 - Flags: review?(darin.moz)
Attachment #256164 - Flags: review?(darin.moz) → review+
Comment on attachment 256164 [details] [diff] [review]
Patch

sr=bzbarsky
Attachment #256164 - Flags: superreview+
Checked in.  Bas, thank you very much for the patch!
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
My pleasure, thanks for the quick reviews.
Is it really necessary to enter the monitor in the nsEventQueue's destructor?  That implies that more than one consumer might have a reference to the nsEventQueue while the nsEventQueue is being destroyed.  How can that be?  If that is possible, then it surely indicates a problem, no?
I don't think it is necessary, no. But it seemed like the safest choice when I contributed the patch, considering the monitor is entered on PutEvent and GetEvent as well. I thought someone who knew the code better might be more able to make the 'right' decision on the usage of the monitor.
Attached patch Remove the monitor-entering. (deleted) — Splinter Review
Attachment #256503 - Flags: superreview?
Attachment #256503 - Flags: review?
Attachment #256503 - Flags: superreview?(darin.moz)
Attachment #256503 - Flags: superreview?
Attachment #256503 - Flags: review?(darin.moz)
Attachment #256503 - Flags: review?
Attachment #256503 - Flags: superreview?(darin.moz)
Attachment #256503 - Flags: superreview+
Attachment #256503 - Flags: review?(darin.moz)
Attachment #256503 - Flags: review+
Checked in that followup patch.
Flags: blocking1.9? → in-testsuite?
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: