From bfcb08b866cd3a6c6fbf798b2eaacb9546ae0167 Mon Sep 17 00:00:00 2001
From: Nick Draper <nick.draper@stfc.ac.uk>
Date: Tue, 13 Oct 2015 15:06:40 +0100
Subject: [PATCH] re #13928 move code to aviod possible memory leak

---
 Vates/VatesAPI/src/vtkMDHistoQuadFactory.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Vates/VatesAPI/src/vtkMDHistoQuadFactory.cpp b/Vates/VatesAPI/src/vtkMDHistoQuadFactory.cpp
index 11af3df2b5b..5413e173b24 100644
--- a/Vates/VatesAPI/src/vtkMDHistoQuadFactory.cpp
+++ b/Vates/VatesAPI/src/vtkMDHistoQuadFactory.cpp
@@ -92,6 +92,12 @@ namespace Mantid
         coord_t incrementX = (maxX - minX) / static_cast<coord_t>(nBinsX);
         coord_t incrementY = (maxY - minY) / static_cast<coord_t>(nBinsY);
 
+        boost::scoped_ptr<MDHistoWorkspaceIterator> iterator(dynamic_cast<MDHistoWorkspaceIterator*>(createIteratorWithNormalization(m_normalizationOption, m_workspace.get())));
+        if (!iterator) {
+          throw std::runtime_error(
+              "Could not convert IMDIterator to a MDHistoWorkspaceIterator");
+        }
+
         const int imageSize = (nBinsX ) * (nBinsY );
         vtkPoints *points = vtkPoints::New();
         points->Allocate(static_cast<int>(imageSize));
@@ -119,11 +125,6 @@ namespace Mantid
 
         double progressFactor = 0.5/double(nBinsX);
         double progressOffset = 0.5;
-        boost::scoped_ptr<MDHistoWorkspaceIterator> iterator(dynamic_cast<MDHistoWorkspaceIterator*>(createIteratorWithNormalization(m_normalizationOption, m_workspace.get())));
-        if (!iterator) {
-          throw std::runtime_error(
-              "Could not convert IMDIterator to a MDHistoWorkspaceIterator");
-        }
 
         size_t index = 0;
         for (int i = 0; i < nBinsX; i++)
-- 
GitLab