Bug 684452 - Memory leak in nsEmlxHelperUtils::AddEmlxMessageToStream. r=bienvenu
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Mon, 13 Feb 2012 20:47:11 +0000
changeset 10822 1717874b0963808d65d3bffa1a750046c11f8068
parent 10821 42b7c8b861b47e8cde7f165b94f5c84ddcd3dac3
child 10823 22c18ee522cbfc1f90bf0d3640d6544186eb408c
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs684452
Bug 684452 - Memory leak in nsEmlxHelperUtils::AddEmlxMessageToStream. r=bienvenu
mailnews/import/applemail/src/nsEmlxHelperUtils.mm
--- a/mailnews/import/applemail/src/nsEmlxHelperUtils.mm
+++ b/mailnews/import/applemail/src/nsEmlxHelperUtils.mm
@@ -218,19 +218,24 @@ nsresult nsEmlxHelperUtils::AddEmlxMessa
   // in the mbox file.
   rv = aOut->Write(X_MOZILLA_KEYWORDS, X_MOZILLA_KEYWORDS_LEN, &dummyRv);
   if (NS_FAILED(rv)) {
     [pool release];
     return rv;
   }
   
   // write out empty X-Mozilla_status2 header
-  char x_mozilla_status_2[40];
-  PR_snprintf(x_mozilla_status_2, sizeof(x_mozilla_status_2), X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, 0);
-  rv = aOut->Write(x_mozilla_status_2, strlen(x_mozilla_status_2), &dummyRv);
+  buf.Adopt(PR_smprintf(X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, 0));
+  NS_ASSERTION(!buf.IsEmpty(), "printf error with X-Mozilla-Status2 header");
+  if (buf.IsEmpty()) {
+    [pool release];
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  rv = aOut->Write(buf.get(), buf.Length(), &dummyRv);
   if (NS_FAILED(rv)) {
     [pool release];
     return rv;
   }
   
   // do any conversion needed for the mbox data to be valid mboxrd.
   nsCString convertedData;
   rv = ConvertToMboxRD(startOfMessageData, (startOfMessageData + numberOfBytesToRead), convertedData);