Bug 604632 nsPrintEngine::DoPrint leaks docTitleStr and docURLStr if !seqFrame
authortimeless@mozdev.org
Sun, 05 Dec 2010 12:43:45 +0000
changeset 58623 8ab66adf43bb070b601c89e9dcbe5e69121399b7
parent 58622 cc14f84709d4ae64e1d09df837dfc7e01cf1936f
child 58624 30b83f45346c6ae6f59cebaddae1a929b2bf2e99
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs604632
milestone2.0b8pre
Bug 604632 nsPrintEngine::DoPrint leaks docTitleStr and docURLStr if !seqFrame r=roc, a=roc
layout/printing/nsPrintEngine.cpp
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2310,114 +2310,114 @@ nsPrintEngine::DoPrint(nsPrintObject * a
         char * urlStr;
         GetDocTitleAndURL(aPO, docStr, urlStr);
         DumpLayoutData(docStr, urlStr, poPresContext, mPrt->mPrintDocDC, rootFrame, docShell, nsnull);
         if (docStr) nsMemory::Free(docStr);
         if (urlStr) nsMemory::Free(urlStr);
       }
 #endif
 
-      if (mPrt->mPrintSettings) {
-        PRUnichar * docTitleStr = nsnull;
-        PRUnichar * docURLStr   = nsnull;
-
-        GetDisplayTitleAndURL(aPO, &docTitleStr, &docURLStr, eDocTitleDefBlank); 
-
-        if (nsIPrintSettings::kRangeSelection == printRangeType) {
-          CloneSelection(aPO->mDocument->GetOriginalDocument(), aPO->mDocument);
-
-          poPresContext->SetIsRenderingOnlySelection(PR_TRUE);
-          // temporarily creating rendering context
-          // which is needed to dinf the selection frames
-          nsCOMPtr<nsIRenderingContext> rc;
-          mPrt->mPrintDC->CreateRenderingContext(*getter_AddRefs(rc));
-
-          // find the starting and ending page numbers
-          // via the selection
-          nsIFrame* startFrame;
-          nsIFrame* endFrame;
-          PRInt32   startPageNum;
-          PRInt32   endPageNum;
-          nsRect    startRect;
-          nsRect    endRect;
-
-          nsCOMPtr<nsISelection> selectionPS;
-          selectionPS = poPresShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
-
-          rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence,
-                                        &startFrame, startPageNum, startRect,
-                                        &endFrame, endPageNum, endRect);
-          if (NS_SUCCEEDED(rv)) {
-            mPrt->mPrintSettings->SetStartPageRange(startPageNum);
-            mPrt->mPrintSettings->SetEndPageRange(endPageNum);
-            nsIntMargin marginTwips(0,0,0,0);
-            nsIntMargin unwrtMarginTwips(0,0,0,0);
-            mPrt->mPrintSettings->GetMarginInTwips(marginTwips);
-            mPrt->mPrintSettings->GetUnwriteableMarginInTwips(unwrtMarginTwips);
-            nsMargin totalMargin = poPresContext->CSSTwipsToAppUnits(marginTwips + 
-                                                                     unwrtMarginTwips);
-            if (startPageNum == endPageNum) {
-              {
-                startRect.y -= totalMargin.top;
-                endRect.y   -= totalMargin.top;
-
-                // Clip out selection regions above the top of the first page
-                if (startRect.y < 0) {
-                  // Reduce height to be the height of the positive-territory
-                  // region of original rect
-                  startRect.height = NS_MAX(0, startRect.YMost());
-                  startRect.y = 0;
-                }
-                if (endRect.y < 0) {
-                  // Reduce height to be the height of the positive-territory
-                  // region of original rect
-                  endRect.height = NS_MAX(0, endRect.YMost());
-                  endRect.y = 0;
-                }
-                NS_ASSERTION(endRect.y >= startRect.y,
-                             "Selection end point should be after start point");
-                NS_ASSERTION(startRect.height >= 0,
-                             "rect should have non-negative height.");
-                NS_ASSERTION(endRect.height >= 0,
-                             "rect should have non-negative height.");
-
-                nscoord selectionHgt = endRect.y + endRect.height - startRect.y;
-                // XXX This is temporary fix for printing more than one page of a selection
-                pageSequence->SetSelectionHeight(startRect.y * aPO->mZoomRatio,
-                                                 selectionHgt * aPO->mZoomRatio);
-
-                // calc total pages by getting calculating the selection's height
-                // and then dividing it by how page content frames will fit.
-                nscoord pageWidth, pageHeight;
-                mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
-                pageHeight -= totalMargin.top + totalMargin.bottom;
-                PRInt32 totalPages = NSToIntCeil(float(selectionHgt) * aPO->mZoomRatio / float(pageHeight));
-                pageSequence->SetTotalNumPages(totalPages);
-              }
-            }
-          }
-        }
-
-        nsIFrame * seqFrame = do_QueryFrame(pageSequence);
-        if (!seqFrame) {
-          SetIsPrinting(PR_FALSE);
-          return NS_ERROR_FAILURE;
-        }
-
-        mPageSeqFrame = pageSequence;
-        mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings, docTitleStr, docURLStr);
-
-        // Schedule Page to Print
-        PR_PL(("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]));
-        StartPagePrintTimer(aPO);
-      } else {
+      if (!mPrt->mPrintSettings) {
         // not sure what to do here!
         SetIsPrinting(PR_FALSE);
         return NS_ERROR_FAILURE;
       }
+
+      PRUnichar * docTitleStr = nsnull;
+      PRUnichar * docURLStr   = nsnull;
+
+      GetDisplayTitleAndURL(aPO, &docTitleStr, &docURLStr, eDocTitleDefBlank);
+
+      if (nsIPrintSettings::kRangeSelection == printRangeType) {
+        CloneSelection(aPO->mDocument->GetOriginalDocument(), aPO->mDocument);
+
+        poPresContext->SetIsRenderingOnlySelection(PR_TRUE);
+        // temporarily creating rendering context
+        // which is needed to dinf the selection frames
+        nsCOMPtr<nsIRenderingContext> rc;
+        mPrt->mPrintDC->CreateRenderingContext(*getter_AddRefs(rc));
+
+        // find the starting and ending page numbers
+        // via the selection
+        nsIFrame* startFrame;
+        nsIFrame* endFrame;
+        PRInt32   startPageNum;
+        PRInt32   endPageNum;
+        nsRect    startRect;
+        nsRect    endRect;
+
+        nsCOMPtr<nsISelection> selectionPS;
+        selectionPS = poPresShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
+
+        rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selectionPS, pageSequence,
+                                      &startFrame, startPageNum, startRect,
+                                      &endFrame, endPageNum, endRect);
+        if (NS_SUCCEEDED(rv)) {
+          mPrt->mPrintSettings->SetStartPageRange(startPageNum);
+          mPrt->mPrintSettings->SetEndPageRange(endPageNum);
+          nsIntMargin marginTwips(0,0,0,0);
+          nsIntMargin unwrtMarginTwips(0,0,0,0);
+          mPrt->mPrintSettings->GetMarginInTwips(marginTwips);
+          mPrt->mPrintSettings->GetUnwriteableMarginInTwips(unwrtMarginTwips);
+          nsMargin totalMargin = poPresContext->CSSTwipsToAppUnits(marginTwips +
+                                                                   unwrtMarginTwips);
+          if (startPageNum == endPageNum) {
+            startRect.y -= totalMargin.top;
+            endRect.y   -= totalMargin.top;
+
+            // Clip out selection regions above the top of the first page
+            if (startRect.y < 0) {
+              // Reduce height to be the height of the positive-territory
+              // region of original rect
+              startRect.height = NS_MAX(0, startRect.YMost());
+              startRect.y = 0;
+            }
+            if (endRect.y < 0) {
+              // Reduce height to be the height of the positive-territory
+              // region of original rect
+              endRect.height = NS_MAX(0, endRect.YMost());
+              endRect.y = 0;
+            }
+            NS_ASSERTION(endRect.y >= startRect.y,
+                         "Selection end point should be after start point");
+            NS_ASSERTION(startRect.height >= 0,
+                         "rect should have non-negative height.");
+            NS_ASSERTION(endRect.height >= 0,
+                         "rect should have non-negative height.");
+
+            nscoord selectionHgt = endRect.y + endRect.height - startRect.y;
+            // XXX This is temporary fix for printing more than one page of a selection
+            pageSequence->SetSelectionHeight(startRect.y * aPO->mZoomRatio,
+                                             selectionHgt * aPO->mZoomRatio);
+
+            // calc total pages by getting calculating the selection's height
+            // and then dividing it by how page content frames will fit.
+            nscoord pageWidth, pageHeight;
+            mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);
+            pageHeight -= totalMargin.top + totalMargin.bottom;
+            PRInt32 totalPages = NSToIntCeil(float(selectionHgt) * aPO->mZoomRatio / float(pageHeight));
+            pageSequence->SetTotalNumPages(totalPages);
+          }
+        }
+      }
+
+      nsIFrame * seqFrame = do_QueryFrame(pageSequence);
+      if (!seqFrame) {
+        SetIsPrinting(PR_FALSE);
+        if (docTitleStr) nsMemory::Free(docTitleStr);
+        if (docURLStr) nsMemory::Free(docURLStr);
+        return NS_ERROR_FAILURE;
+      }
+
+      mPageSeqFrame = pageSequence;
+      mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings, docTitleStr, docURLStr);
+
+      // Schedule Page to Print
+      PR_PL(("Scheduling Print of PO: %p (%s) \n", aPO, gFrameTypesStr[aPO->mFrameType]));
+      StartPagePrintTimer(aPO);
     }
   }
 
   return NS_OK;
 }
 
 //---------------------------------------------------------------------
 void