Bug 642902 - If a profile's invalid, we leak it. Don't. r=jrmuizel
authorJoe Drew <joe@drew.ca>
Wed, 23 Mar 2011 12:20:43 -0400
changeset 63670 952373d0334eb7fda761843cc59c7e850733939f
parent 63669 e44b2614a7bc57d752844a9e529e833d1f958975
child 63671 0fdc05b3cd03193ab85d66d42eb82e815483bfc4
push id19248
push usereakhgari@mozilla.com
push dateWed, 23 Mar 2011 23:19:35 +0000
treeherdermozilla-central@ab95ab9e389b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs642902
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 642902 - If a profile's invalid, we leak it. Don't. r=jrmuizel
modules/libpr0n/decoders/nsJPEGDecoder.cpp
--- a/modules/libpr0n/decoders/nsJPEGDecoder.cpp
+++ b/modules/libpr0n/decoders/nsJPEGDecoder.cpp
@@ -79,16 +79,30 @@ namespace imagelib {
 #if defined(PR_LOGGING)
 PRLogModuleInfo *gJPEGlog = PR_NewLogModule("JPEGDecoder");
 static PRLogModuleInfo *gJPEGDecoderAccountingLog = PR_NewLogModule("JPEGDecoderAccounting");
 #else
 #define gJPEGlog
 #define gJPEGDecoderAccountingLog
 #endif
 
+static qcms_profile*
+GetICCProfile(struct jpeg_decompress_struct &info)
+{
+  JOCTET* profilebuf;
+  PRUint32 profileLength;
+  qcms_profile* profile = nsnull;
+
+  if (read_icc_profile(&info, &profilebuf, &profileLength)) {
+    profile = qcms_profile_from_memory(profile, profileLength);
+    free(profilebuf);
+  }
+
+  return profile;
+}
 
 METHODDEF(void) init_source (j_decompress_ptr jd);
 METHODDEF(boolean) fill_input_buffer (j_decompress_ptr jd);
 METHODDEF(void) skip_input_data (j_decompress_ptr jd, long num_bytes);
 METHODDEF(void) term_source (j_decompress_ptr jd);
 METHODDEF(void) my_error_exit (j_common_ptr cinfo);
 
 /* Normal JFIF markers can't have more bytes than this. */
@@ -243,24 +257,18 @@ nsJPEGDecoder::WriteInternal(const char 
     // Post our size to the superclass
     PostSize(mInfo.image_width, mInfo.image_height);
 
     /* If we're doing a size decode, we're done. */
     if (IsSizeDecode())
       return;
 
     /* We're doing a full decode. */
-    JOCTET  *profile;
-    PRUint32 profileLength;
-
-    if ((mCMSMode != eCMSMode_Off) &&
-        read_icc_profile(&mInfo, &profile, &profileLength) &&
-        (mInProfile = qcms_profile_from_memory(profile, profileLength)) != NULL) {
-      free(profile);
-
+    if (mCMSMode != eCMSMode_Off &&
+        (mInProfile = GetICCProfile(mInfo)) != nsnull) {
       PRUint32 profileSpace = qcms_profile_get_color_space(mInProfile);
       PRBool mismatch = PR_FALSE;
 
 #ifdef DEBUG_tor
       fprintf(stderr, "JPEG profileSpace: 0x%08X\n", profileSpace);
 #endif
       switch (mInfo.jpeg_color_space) {
       case JCS_GRAYSCALE: