Closed Bug 684452 Opened 9 years ago Closed 9 years ago

Memory leak in nsEmlxHelperUtils::AddEmlxMessageToStream

Categories

(MailNews Core :: Import, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 13.0

People

(Reporter: hiro, Assigned: hiro)

Details

(Keywords: memory-leak)

Attachments

(1 file, 3 obsolete files)

The return value of PR_smprintf should be freed by PR_smprintf_free.
Attached patch Proposed fix (obsolete) — Splinter Review
I have no build environment for Mac OS X, so I don't build comm-central on Mac OS X with this patch.
Attachment #558043 - Flags: review?(dbienvenu)
Comment on attachment 558043 [details] [diff] [review]
Proposed fix

Fly-by comment: Doing this might be slightly nicer:

nsCAutoString buf;
buf.Adopt(PR_smprintf(X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, x_mozilla_flags));

Then you don't have to worry about what size the memory is.
Attached patch Revised patch (obsolete) — Splinter Review
Follow Mark's comment.

> nsCAutoString buf;
> buf.Adopt(PR_smprintf(X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK,
> x_mozilla_flags));
> 
> Then you don't have to worry about what size the memory is.

I did not know the Adopt method. Thanks for the advice!
Attachment #558043 - Attachment is obsolete: true
Attachment #558043 - Flags: review?(dbienvenu)
Attachment #558248 - Flags: review?(dbienvenu)
Also use Adopt for X-Mozilla-Status2 header.
Assignee: nobody → hiikezoe
Attachment #558249 - Flags: review?(dbienvenu)
Comment on attachment 558248 [details] [diff] [review]
Revised patch

Review of attachment 558248 [details] [diff] [review]:
-----------------------------------------------------------------

::: mailnews/import/applemail/src/nsEmlxHelperUtils.mm
@@ +206,5 @@
>    NS_ASSERTION(!buf.IsEmpty(), "printf error with X-Mozilla-Status header");
>    if (buf.IsEmpty()) {
>      [pool release];
>      return rv;
>    }

The return value of this failure case seems to be NS_OK. Should return error value? Should I open a new bug for it?
bienvenu?

(In reply to Hiroyuki Ikezoe (:hiro) from comment #5)
> Comment on attachment 558248 [details] [diff] [review]
> Revised patch
> 
> Review of attachment 558248 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: mailnews/import/applemail/src/nsEmlxHelperUtils.mm
> @@ +206,5 @@
> >    NS_ASSERTION(!buf.IsEmpty(), "printf error with X-Mozilla-Status header");
> >    if (buf.IsEmpty()) {
> >      [pool release];
> >      return rv;
> >    }
> 
> The return value of this failure case seems to be NS_OK. Should return error
> value? Should I open a new bug for it?
Severity: normal → minor
Keywords: mlk
Comment on attachment 558249 [details] [diff] [review]
Rewrite with Adopt for X-Mozilla-Status2 header

sorry for the delay - I think in out of memory, you want to return NS_ERROR_OUT_OF_MEMORY, not rv. Other than that, it looks OK (except for the question of whether the allocator aborts the app in the case of out of memory, in which case this code wouldn't be hit).
Attachment #558249 - Flags: review?(dbienvenu) → review-
Comment on attachment 558248 [details] [diff] [review]
Revised patch

thx for the patch
Attachment #558248 - Flags: review?(dbienvenu) → review+
Attachment #558249 - Attachment is obsolete: true
Attachment #591689 - Flags: review?(dbienvenu)
Comment on attachment 591689 [details] [diff] [review]
Return NS_ERROR_OUT_OF_MEMORY instead of rv.

thx for the patch...
Attachment #591689 - Flags: review?(dbienvenu) → review+
Keywords: checkin-needed
Comment on attachment 558248 [details] [diff] [review]
Revised patch

I understand this patch isn't required, so marking obsolete.
Attachment #558248 - Attachment is obsolete: true
Summary: Memory leak in nsEmlxHelperUtils::AddEmlxMessa → Memory leak in nsEmlxHelperUtils::AddEmlxMessageToStream
Checked in: http://hg.mozilla.org/comm-central/rev/1717874b0963
Status: NEW → RESOLVED
Closed: 9 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 13.0
You need to log in before you can comment on or make changes to this bug.