Closed
Bug 273022
Opened 20 years ago
Closed 19 years ago
early returns cause remaining voidarray members to leak
Categories
(Core Graveyard :: Plug-ins, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: timeless, Assigned: jlurz24)
References
()
Details
(Keywords: helpwanted, memory-leak)
Attachments
(1 file, 1 obsolete file)
|
3.35 KB,
patch
|
jst
:
review+
jst
:
superreview+
|
Details | Diff | Splinter Review |
yes this is a dupe, but i want someone else to fix it right, the first time. the url contains code flow analysis, if you can't figure out what's going on from the link then you aren't the right person to fix this bug. if you're interested in fixing this bug, other developers on irc will gladly help.
Updated•20 years ago
|
Assignee: nobody → jonathan.watt
Summary: early returns cause remaining voidarray members to leak → early returns cause remaining voidarray members to leak
Adds a simple helper object which deallocates the contents of the array when it goes out of scope.
Attachment #208271 -
Flags: review?(timeless)
Comment 2•19 years ago
|
||
Crap! The URL I use to get the list of my current bugs has prevented me from seeing this one. Totally forgot about it. Sorry! jpl24: feel free to take this.
Comment 3•19 years ago
|
||
Minor nit, I think the helper class should be moved down to just above the function that uses it rather than several functions above. If someone's ambitious enough, all this logic could be refactored better. I think the helper class could provide a nice abstraction and serve more than just cleanup. Have the constructor build the list and sort. Provide either an enumeration interface or array accessor. Then have the following loop use that instead of nsAutoVoidArray. But this patch is good as it is, since it takes care of the leak.
Comment 4•19 years ago
|
||
Note that when it works this should just use nsTArray<nsAutoPtr<pluginFileinDirectory>> to start with. Then it will all Just Work.
If the nsTArray functions like a standard library vector(I think it does), only reference counted pointers are allowed in an nsTArray. I remember some comments in the nsTArray bug talking about this issue, maybe that has changed since I read the bug. I had originally considered using nsRefPtrs, but I believe that would require the struct inheriting from nsISupports, and I thought the addrefing might slow down the sort. The original version of the patch I wrote actually converted the nsVoidArray into an nsTArray, but I thought given that this code seemed pretty fragile it might be better to make the code changes as small as possible. So I trimmed the patch down to the bare minimum. I'm of course happy to redo the patch in whatever is thought to be best from a perf/code maintenance standpoint.
Comment 6•19 years ago
|
||
Right. Hence the "when it works" part of my comment... ;)
Whoops, reading was never my strength. This is probably the topic for another bug, but boost(C++ standard library extension), has a vector specifically for this purpose. I think it's called ptr_vector, and it doesn't do any reference counting but deletes all it's contained pointers memory when it's done. Handy for avoiding leaks without hurting performance. http://www.boost.org/libs/ptr_container/doc/ptr_container.html
Comment 8•19 years ago
|
||
I'd be all for using Boost code. I'm not sure if there are any licensing issues or portabilities issues. The latter may be the kicker since, while Boost is portable, I'm not sure they cater to all the platforms Mozilla does. But this is no longer bug dicussion but architecture and should be discussed elsewhere.
Move definition of the helper class directly before the function. I agree there is definitely room for more use of the helper class, I'll file a follow up bug on that after the leak is fixed.
Attachment #208271 -
Attachment is obsolete: true
Attachment #208711 -
Flags: review?(jst)
Attachment #208271 -
Flags: review?(timeless)
Comment 10•19 years ago
|
||
Comment on attachment 208711 [details] [diff] [review] patch_v2 r+sr=jst
Attachment #208711 -
Flags: superreview+
Attachment #208711 -
Flags: review?(jst)
Attachment #208711 -
Flags: review+
| Assignee | ||
Comment 11•19 years ago
|
||
I don't have a CVS account, so if somebody could commit this when they get a chance that'd be great. Thanks!
Updated•19 years ago
|
Assignee: jwatt → jlurz24
Comment 12•19 years ago
|
||
Checked in on the trunk. Thanks for the patch!
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Updated•2 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•