From 572d40007e49404f7381f53ba5e3f5881e54e997 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Sat, 24 Oct 2009 18:02:26 +0300 Subject: [PATCH] Bug 521608 - nsCanvasRenderingContext2D::GetPresShell may crash or leak, r=vlad, sr=jst --- content/canvas/src/nsCanvasRenderingContext2D.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index f0287d904ee..4d357ecaf81 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -488,14 +488,17 @@ protected: * Gets the pres shell from either the canvas element or the doc shell */ nsIPresShell *GetPresShell() { - nsIPresShell *presShell = nsnull; nsCOMPtr content = do_QueryInterface(mCanvasElement); if (content) { - presShell = content->GetOwnerDoc()->GetPrimaryShell(); - } else if (mDocShell) { - mDocShell->GetPresShell(&presShell); + nsIDocument* ownerDoc = content->GetOwnerDoc(); + return ownerDoc ? ownerDoc->GetPrimaryShell() : nsnull; } - return presShell; + if (mDocShell) { + nsCOMPtr shell; + mDocShell->GetPresShell(getter_AddRefs(shell)); + return shell.get(); + } + return nsnull; } // text