Closed Bug 413424 Opened 14 years ago Closed 14 years ago

PNG encoder leaks a string

Categories

(Core :: ImageLib, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9beta3

People

(Reporter: Dolske, Assigned: Dolske)

References

Details

(Keywords: memory-leak)

Attachments

(1 file)

Attached patch Patch v.1Splinter Review
Caught this while looking at Solaris leaks with libumem. Doh, my bad, I wrote this code. :)
Attachment #298382 - Flags: review?(pavlov)
Assignee: nobody → dolske
Target Milestone: --- → mozilla1.9 M11
Attachment #298382 - Flags: review?(pavlov) → review+
Attachment #298382 - Flags: approval1.9?
Comment on attachment 298382 [details] [diff] [review]
Patch v.1

a1.9 Not sure whether to be angry you leaked or happy you fixed it :-).
Attachment #298382 - Flags: approval1.9? → approval1.9+
Let's go with "happy". :-)

Checking in modules/libpr0n/encoders/png/nsPNGEncoder.cpp;
/cvsroot/mozilla/modules/libpr0n/encoders/png/nsPNGEncoder.cpp,v  <--  nsPNGEncoder.cpp
new revision: 1.7; previous revision: 1.6
done
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Comment on attachment 298382 [details] [diff] [review]
Patch v.1

>-  char* options = nsCRT::strdup(PromiseFlatCString(NS_ConvertUTF16toUTF8(aOptions)).get());

For future reference, NS_ConvertXXXtoYYY is always flat, it has a .get() method, so no need for the PromiseFlat(C)String.

>+  // Make a copy of aOptions, because strtok() will modify it.
>+  nsCAutoString optionsCopy;
>+  optionsCopy.Assign(NS_ConvertUTF16toUTF8(aOptions));

Here you can avoid one buffer copy if you use CopyUTF16toUTF8(aOptions, optionsCopy);
You need to log in before you can comment on or make changes to this bug.