Closed Bug 336914 Opened 20 years ago Closed 20 years ago

mAdoptFreeCount not maintained correctly

Categories

(Core :: XPCOM, defect, P2)

x86
Linux
defect

Tracking

()

RESOLVED FIXED
mozilla1.9alpha1

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

Attachments

(1 file)

I decided to track down this output from startup + shutdown: => mAdoptCount: 1507 => mAdoptFreeCount: 1478 -- LEAKED 29 !!! As far as I can tell, this happens because mAdoptFreeCount is incorrect. Specifically, calling nsTAdoptingString_CharT::operator=( const self_type& str ) will increment mAdoptCount by 1 but not change mAdoptFreeCount, which is wrong since the buffer just got passed from one string to another. Unfortunately, all the logging code is in a different file (nsSubString.cpp, to be exact). So I can't just add a logging statement here. Perhaps we should simply move all of nsTString.cpp (which is just the constructor in question) into nsTSubString.cpp?
Blocks: 295660
Good catch. You could just avoid calling Adopt and set the member fields directly. The important thing to do is to properly finalize the existing string who's members are being replaced with the adopted value.
Blocks: 311120
For what it's worth, I found this by just adding ctor/dtor logging for the buffer when we adopt/adoptfree and then looking at the adopt stacks not matched by free.... Not sure whether we want to add that to the tree permanently; let me know.
Yeah, even if only as an optional #ifdef, I think that'd be great.
Attachment #221117 - Flags: superreview?(darin)
Attachment #221117 - Flags: review?(darin)
Assignee: nobody → bzbarsky
Priority: -- → P2
Target Milestone: --- → mozilla1.9alpha
Comment on attachment 221117 [details] [diff] [review] This seems to work s/refcound/refcount/
Attachment #221117 - Flags: superreview?(darin)
Attachment #221117 - Flags: superreview+
Attachment #221117 - Flags: review?(darin)
Attachment #221117 - Flags: review+
Fixed.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
This patch, in combination with the static string detector, blows up on Windows; nsLocalFileWin::Load calls IsFile calls ResolveAndStat which does lots of string manipulation, unfortunately while the static string detector is active. Note that the static string detector does otherwise work in that it found a host of static strings in nsWindowsHooks[Utils].cpp which I recently fixed.
I don't really know anything about the static string detector. How does this patch affect it?
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: