Closed
Bug 115815
Opened 23 years ago
Closed 23 years ago
nsFormSubmitter leaks like a sieve
Categories
(Core Graveyard :: File Handling, defect, P2)
Core Graveyard
File Handling
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: hwaara, Assigned: nivedita)
Details
(Keywords: memory-leak)
Attachments
(3 files)
8.08 KB,
patch
|
Details | Diff | Splinter Review | |
16.80 KB,
patch
|
Details | Diff | Splinter Review | |
16.63 KB,
patch
|
bzbarsky
:
review+
jag+mozilla
:
superreview+
|
Details | Diff | Splinter Review |
nsFormSubmitter leaks a lot of strings and stuff.
Comment 1•23 years ago
|
||
Isn't this just a dup of the "clean up this function" bug? Or are there issues
throughout the file?
Comment 2•23 years ago
|
||
Nevermind. I got it... :)
Status: NEW → ASSIGNED
Priority: -- → P2
Target Milestone: --- → mozilla0.9.8
Reporter | ||
Comment 3•23 years ago
|
||
I filed this before commenting in the other bug, and you read your bugmail
sorted by date. Right? :-)
Comment 4•23 years ago
|
||
yup
Assignee | ||
Comment 5•23 years ago
|
||
Håkan Waara
Can you please elaborate the bug description. And can you please enclose the
testcases if any and observations supporting the bug, so as to help me in
cornering the bug.
Comment 6•23 years ago
|
||
Nivedita, see bug 112973, comment #7 and bug 112973 comment #15 (this bug is
meant to address the latter, really).
Keywords: nsbeta1
Hardware: PC → All
Assignee | ||
Comment 7•23 years ago
|
||
Added a class nsStringAutoArrayPtr which handles the deletion of nsString
array. Used nsCAutoString instead of char* so as to create local variables on
stack.
Comment 8•23 years ago
|
||
Do you really need the |char *| versions of the strings _and_ the
|nsCAutoString| versions? Why are the char* versions needed at all?
Assignee | ||
Comment 9•23 years ago
|
||
Eliminated the redundant usage of char*.
Comment 10•23 years ago
|
||
> + nsCAutoString fname;
Transfer the comment about "path removed" as well?
> + if (!name.get()) {
Wouldn't this be better as |if (name.IsEmpty()) {| ? Same thing for
!value.get()
> + name.Adopt(ToNewCString(names[valueX]));
Is there a reason to allocate this on the stack? Wouldn't it make more sense to
do |name = NS_ConvertUCS2toUTF8(names[valueX]);| ?
> + value.Adopt(nsLinebreakConverter::ConvertLineBreaks(value.get(),
Is this safe? I know strings have some issues with things like | foo = bar +
foo | at times due to lazy copying (normally a good thing). This is not exactly
the same, but please test this well....
> PL_strlen(name.get())
Just use name.Length() ? Same thing for fname.
> + PL_strlen(value.get())) { // Don't bother if no file specified
Use !value.IsEmpty() instead -- it's much faster, for one thing.
One problem I see with using .get() and autostrings is embedded nulls in the
strings... Are those a possible issue here? If so, how does Adopt() handle
those?
Assignee | ||
Comment 11•23 years ago
|
||
Using the nsCAutoString methods for getting the length and for check if empty.
if we use name = NS_ConvertUCS2toUTF8(names[valueX]), this also causes realloc
when the Assign method is called when the value is getting assigned to name,
hence the essence of avoiding the alloc using ToNewCString is lost. Please
convey if I am missing something here.
And the problem of using nsCAutoStrings was already existing, as char* were
used. Hence we could address this issue as an another bug
Reporter | ||
Comment 12•23 years ago
|
||
Reassign to nivedita who's working on this now.
Isn't this new |nsStringAutoArrayPtr| class something we'd want globally (i.e.
as a public string class in the strings module)? Jag?
Assignee: bzbarsky → nivedita
Status: ASSIGNED → NEW
Target Milestone: mozilla0.9.8 → ---
Comment 13•23 years ago
|
||
> this also causes realloc when the Assign method is called when the value is
> getting assigned to name
Only if the value is more than 80 characters long. Auto strings have a
stack-allocated internal buffer that holds 80 characters. They don't allocate
unless asked to hold more than that. In this case, this is the name of a form
control, so 80 characters is not likely to be exceeded.
The last patch looks good, though. r=bzbarsky
Updated•23 years ago
|
Attachment #63487 -
Flags: review+
Comment 14•23 years ago
|
||
We already have an nsAutoArrayPtr which you could use here:
xpcom/base/nsAutoPtr.h
TestAutoPtr.cpp in the same directory shows how to use it.
For now the Adopt(ToNewCString(...)) method is not encouraged. Soon I'll add
generating converters which will enable us to skip the second allocation on
Append (string sharing should take care of this on Assign).
Comment 15•23 years ago
|
||
Had spoken to dbaron about nsAutoPtr and he had said that this was work in
progress. We can switch to this once we this header file is gets published to
dist/include/xpcom/. Until then, we would need our local AutoPtr class. This was
my suggestion to Nivedita.
How would u want us to handle the Adopt(ToNewCString(...)) ? Is there an
alternative that we are missing ?
Comment 16•23 years ago
|
||
No, Adopt(ToNewCString()) is probably what you should use for now.
Comment 17•23 years ago
|
||
Can someone do a super review for this and check this in please ? None of us
have checkin access at this point.
Comment 18•23 years ago
|
||
Comment on attachment 63487 [details] [diff] [review]
Incorporated the comments given by Boris Zbarsky
Could you add a comment pointing to dbaron's nsAutoArray and a suggestion that
the code be switched to that once it's been made public?
sr=jag with that.
Attachment #63487 -
Flags: superreview+
Comment 19•23 years ago
|
||
Comments added and checked in.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Updated•8 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•