diff --git a/Plugin/AnalyseMeshQuality.cpp b/Plugin/AnalyseMeshQuality.cpp
index fb181966aa698147716a74e81be4212781db411a..9d9f9e52d24aeb9b748b2628d85aa7f308cd92ba 100644
--- a/Plugin/AnalyseMeshQuality.cpp
+++ b/Plugin/AnalyseMeshQuality.cpp
@@ -177,6 +177,7 @@ PView *GMSH_AnalyseMeshQualityPlugin::execute(PView *v)
 #endif
 
   // Create PView
+  PView *view = nullptr;
   if(createView) {
     for(int dim = 1; dim <= 3; ++dim) {
       if((askedDim == 4 && dim > 1) || dim == askedDim) {
@@ -197,7 +198,7 @@ PView *GMSH_AnalyseMeshQualityPlugin::execute(PView *v)
           if(dataPV.size()) {
             std::stringstream name;
             name << "minJ/maxJ " << dim << "D";
-            new PView(name.str().c_str(), "ElementData", _m, dataPV);
+            view = new PView(name.str().c_str(), "ElementData", _m, dataPV);
           }
         }
         if(!_pviewIGE[dim - 1] && computeIGE) {
@@ -211,7 +212,7 @@ PView *GMSH_AnalyseMeshQualityPlugin::execute(PView *v)
           if(dataPV.size()) {
             std::stringstream name;
             name << "IGE " << dim << "D";
-            new PView(name.str().c_str(), "ElementData", _m, dataPV);
+            view = new PView(name.str().c_str(), "ElementData", _m, dataPV);
           }
         }
         if(!_pviewICN[dim - 1] && computeICN) {
@@ -225,7 +226,7 @@ PView *GMSH_AnalyseMeshQualityPlugin::execute(PView *v)
           if(dataPV.size()) {
             std::stringstream name;
             name << "ICN " << dim << "D";
-            new PView(name.str().c_str(), "ElementData", _m, dataPV);
+            view = new PView(name.str().c_str(), "ElementData", _m, dataPV);
           }
         }
       }
@@ -242,7 +243,7 @@ PView *GMSH_AnalyseMeshQualityPlugin::execute(PView *v)
 #endif
   }
 
-  return nullptr;
+  return view;
 }
 
 void GMSH_AnalyseMeshQualityPlugin::_computeMinMaxJandValidity(int dim)
diff --git a/demos/api/mesh_quality.py b/demos/api/mesh_quality.py
index 2660c739c1ae845bb8b0bfa377e349c74447ac60..2289b89e2ebdd4916eb9a25ca2488813f2342ffb 100644
--- a/demos/api/mesh_quality.py
+++ b/demos/api/mesh_quality.py
@@ -9,9 +9,9 @@ gmsh.model.mesh.generate(3)
 
 gmsh.plugin.setNumber("AnalyseMeshQuality", "ICNMeasure", 1.)
 gmsh.plugin.setNumber("AnalyseMeshQuality", "CreateView", 1.)
-gmsh.plugin.run("AnalyseMeshQuality")
+t = gmsh.plugin.run("AnalyseMeshQuality")
 
-dataType, tags, data, time, numComp = gmsh.view.getModelData(0, 0)
+dataType, tags, data, time, numComp = gmsh.view.getModelData(t, 0)
 
 print('ICN for element {0} = {1}'.format(tags[0], data[0]))