Open Bug 58423 Opened 24 years ago Updated 2 years ago

mTitle.ToNewCString(); not assigned to anything

Categories

(Core :: XUL, defect, P3)

x86
Windows 95
defect

Tracking

()

Future

People

(Reporter: jag+mozbugs, Unassigned)

References

()

Details

Attachments

(3 files)

313   char *title = ConvertToFileSystemCharset(mTitle.GetUnicode());
314   if (nsnull == title)
315     mTitle.ToNewCString();

Line 315 should probably be something like line 124:
122   char *title = ConvertToFileSystemCharset(mTitle.GetUnicode());
123   if (nsnull == title)
124     title = mTitle.ToNewCString();
Adding keywords, attaching patch.
Keywords: patch, review
This is a leak. Not a serious one, but still a leak. Making summary a bit more
clear on that.
Summary: mTitle.ToNewCString(); not assigned to anything → [mlk] mTitle.ToNewCString(); not assigned to anything
CVS blame says nhotta wrote that, reassigning.
Assignee: trudelle → nhotta
r=nhotta
I added the mlk keyword, can you remove the summary [mlk] noise-word?

It seems this code always used delete[] title (in both places) if title was
non-null, yet it wanted to set title from the ConvertToFileSystemCharset, which
returns new char[], or failing that, from the ToNewCString result, which IIRC
returns nsMemory::Alloc'd code.  So doesn't this mean that sometimes, purify
will complain about a mismatch?

I say fix ConvertToFileSystemCharset to use nsMemory too.

/be
Keywords: mlk
I agree with changing it to use nsMemory.
I think ToNewCString used to be freed by delete[].
Status: NEW → ASSIGNED
Summary: [mlk] mTitle.ToNewCString(); not assigned to anything → mTitle.ToNewCString(); not assigned to anything
disttsc@bart.nl, do you also want to do the memory allocation change?
Here's a first cut... I don't have access to a Windows machine to test compile
on though (and hunting someone down in #mozilla has so far proven unsuccessful),
so this is untested. I've currently only changed the (de)allocations for the
functions and variables directly affected, if so desired changing
ConvertFromFileSystemCharset and its callers shouldn't be too hard either.
Thanks, please also change ConvertFromFileSystemCharset.
Since I only know the code around the charset conversion, you should also get a
review from the module owner of this file.
nhotta: check patch #3 ;-)
r=nhotta
It compiled on windows.
As I said, the first half of the patch does not related to charset conversion,
please find a module owner of widget to get a review.

I tested with the patch, and put a break point at nsFileWidget::Show but it
didn't break when I used open dialog and save dialog. The code might not be used
anymore.
Cc to pinketon. Mike, who is a module owner of widget? I cannot find in
http://www.mozilla.org/owners.html

there is no real module owner for widget, though rods claims it for win32, pav
claims it for linux, and we tagteam for mac.
jag: you inverted some if (NULL == converted), etc., tests and used if
(converted), which is cool -- I don't see any incompatible change there, but I
question the original code (which you didn't write) covering up out-of-memory
errors.  Worth fixing now?  Do in a later bug?  XXX comment now if the latter.

Here is a change I think that's not compatible, or a bugfix:


-         if (NS_SUCCEEDED(rv)) 
-                 rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName,
aCharset);
-
     NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
-         if (NS_FAILED(rv)) 
-                 aCharset.AssignWithConversion("windows-1252");
+
+    if (NS_SUCCEEDED(rv)) 
+      rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);
+    else
+      aCharset.AssignWithConversion("windows-1252");

The old code would fall back on "windows-1252" if anything failed, early or
late.  You fall back only in the earlier failure, and ignore a later failure in
GetCharset.  See what I mean?

/be
Doh! Yes, I see what you mean. I thought I had checked for that...
Okay, so I'll undo that whole change :-)

Re: out-of-memory errors: looking into it.

cc'ing rods for review / input on this code.
We can check in the first patch for the memory leak now. I'll ask brendan for an
approval.
Sure -- sr= on the first patch, but please finish up the related cleanups too,
they make the code significantly better, and should not be dropped on the floor.
 Thanks,

/be
sr=brendan@mozilla.org on the first (one-line) patch, I mean.

/be
Checked in the first patch, remove mlk keyword.
Keywords: mlk
Cool, thanks :-)

nhotta:
Shall I attach the last patch with the correction Brendan pointed out?

I can look at his other comments (current out of memory cover-ups, converting to
String code istead of manually allocating/freeing memory) later this month, so
if you can do that sooner, that'd be cool.
Yes, please attach the patch.
I reassign to you since you're actually fixing it. I can help you to check in.
Also please get a review from xptool kit group like rods since the rest of the
changes are mostly not in international code.
Assignee: nhotta → disttsc
Status: ASSIGNED → NEW
Mass move to jaggernaut@netscape.com
Assignee: jag → jaggernaut
->future
Target Milestone: --- → Future
Assignee: jag → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: