From 5e0f7563751bd7a7273430b523ab61eee18cd0dc Mon Sep 17 00:00:00 2001
From: Jean-Francois Remacle <jean-francois.remacle@uclouvain.be>
Date: Mon, 25 Jun 2001 13:30:57 +0000
Subject: [PATCH] Memory pb fixes.

---
 Mesh/2D_Links.cpp   |  4 +++-
 Mesh/2D_Mesh.cpp    | 11 ++++++++++-
 Mesh/Generator.cpp  |  9 ++++++++-
 Mesh/Print_Mesh.cpp |  8 ++++----
 Mesh/Read_Mesh.cpp  | 12 ++++++------
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/Mesh/2D_Links.cpp b/Mesh/2D_Links.cpp
index ad8f06a285..51a52883cd 100644
--- a/Mesh/2D_Links.cpp
+++ b/Mesh/2D_Links.cpp
@@ -1,4 +1,4 @@
-// $Id: 2D_Links.cpp,v 1.7 2001-04-08 20:36:49 geuzaine Exp $
+// $Id: 2D_Links.cpp,v 1.8 2001-06-25 13:30:57 remacle Exp $
 
 #include "Gmsh.h"
 #include "Const.h"
@@ -79,6 +79,8 @@ int Conversion(DocPeek doc ){
   /* nombre de triangles que l'on doit obtenir */
   count2 = 2 * (n - 1) - count2;        
         
+  if(doc->delaunay)Free (doc->delaunay);
+
   doc->delaunay = (Delaunay *) Malloc(2*count2 * sizeof(Delaunay));
 
   for (i=0;i<n;i++){
diff --git a/Mesh/2D_Mesh.cpp b/Mesh/2D_Mesh.cpp
index 4c85908fe5..2ed9ba2226 100644
--- a/Mesh/2D_Mesh.cpp
+++ b/Mesh/2D_Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: 2D_Mesh.cpp,v 1.27 2001-06-06 21:29:58 remacle Exp $
+// $Id: 2D_Mesh.cpp,v 1.28 2001-06-25 13:30:57 remacle Exp $
 
 /*
    Maillage Delaunay d'une surface (Point insertion Technique)
@@ -456,6 +456,7 @@ int mesh_domain (ContourPeek * ListContours, int numcontours,
   gPointArray = doc->points;
 
   numaloc = nump;
+  doc->delaunay = 0;
   doc->numPoints = nump;
   doc->numTriangles = 0;
   mai->numtriangles = 0;
@@ -819,6 +820,9 @@ int mesh_domain (ContourPeek * ListContours, int numcontours,
       mai->listdel[i]->t.b = a;
     }
   }
+  // MEMORY LEAK (JF)
+  //  Free(doc->delaunay);
+  //  doc->delaunay = 0;
   return 1;
 }
 
@@ -929,7 +933,11 @@ void Maillage_Automatique_VieuxCode (Surface * pS, Mesh * m, int ori){
       s->iEnt = pS->Num;
       Tree_Insert (pS->Simplexes, &s);
     }
+    // MEMORY LEAK (JF)
+    //    Free(M.listdel[i]);
   }
+  // ANOTHER ONE (JF)
+  Free (M.listdel);
   Free (gPointArray);
 }
 
@@ -938,6 +946,7 @@ void Make_Mesh_With_Points (DocRecord * ptr, PointRecord * Liste, int Numpoints)
   ptr->numTriangles = 0;
   ptr->points = Liste;
   ptr->numPoints = Numpoints;
+  ptr->delaunay = 0;
   DelaunayAndVoronoi (ptr);
   Conversion (ptr);
   remove_all_dlist (ptr->numPoints, ptr->points);
diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp
index 369f1f0193..b884eb77bc 100644
--- a/Mesh/Generator.cpp
+++ b/Mesh/Generator.cpp
@@ -1,4 +1,4 @@
-// $Id: Generator.cpp,v 1.21 2001-06-25 13:05:16 geuzaine Exp $
+// $Id: Generator.cpp,v 1.22 2001-06-25 13:30:57 remacle Exp $
 
 #include "Gmsh.h"
 #include "Const.h"
@@ -242,6 +242,13 @@ void mai3d (Mesh * M, int Asked){
       (Asked < oldstatus && Asked > 1)){
     Msg(STATUS2, "Mesh 2D...");
     t1 = Cpu();
+
+    if(M->status == 3)
+      {
+	OpenProblem (CTX.filename);
+	Maillage_Dimension_1 (M);
+      }
+
     Maillage_Dimension_2 (M);
     t2 = Cpu();
     Msg(STATUS2, "Mesh 2D complete (%g s)", t2 - t1);
diff --git a/Mesh/Print_Mesh.cpp b/Mesh/Print_Mesh.cpp
index 64f8296975..aa0c15e806 100644
--- a/Mesh/Print_Mesh.cpp
+++ b/Mesh/Print_Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Print_Mesh.cpp,v 1.22 2001-06-25 13:05:16 geuzaine Exp $
+// $Id: Print_Mesh.cpp,v 1.23 2001-06-25 13:30:57 remacle Exp $
 
 #include "Gmsh.h"
 #include "Const.h"
@@ -133,16 +133,16 @@ void add_msh_simplex (void *a, void *b){
       type = TETRAHEDRON;
   }
   
-#if 0 // JF, je comprends pas !?
+#if 1 // JF, je comprends pas !?
   if(type == TETRAHEDRON)
     {
-      if ((*S)->Volume_Simplexe () > 0){
+      if ((*S)->Volume_Simplexe () < 0){
         Vertex *temp;
         temp = (*S)->V[0];
         (*S)->V[0] = (*S)->V[1];
         (*S)->V[1] = temp;
 	//        if ((*S)->Volume_Simplexe () < 0)
-          Msg(WARNING, "Negative volume for simplex %d", (*S)->Num);
+	//          Msg(WARNING, "Negative volume for simplex %d", (*S)->Num);
       }
     }
 #endif
diff --git a/Mesh/Read_Mesh.cpp b/Mesh/Read_Mesh.cpp
index ea48cf249f..e245d4d0f2 100644
--- a/Mesh/Read_Mesh.cpp
+++ b/Mesh/Read_Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Read_Mesh.cpp,v 1.16 2001-06-02 19:44:35 remacle Exp $
+// $Id: Read_Mesh.cpp,v 1.17 2001-06-25 13:30:57 remacle Exp $
 
 #include "Gmsh.h"
 #include "Geo.h"
@@ -144,11 +144,11 @@ void Read_Mesh_MSH (Mesh *M, FILE *File_GEO){
 	    
 	    switch(Type){
 	    case LGN1:
-	      simp = Create_Simplex(vertsp[0], vertsp[1], NULL , NULL);
-	      simp->Num = Num ;
-	      simp->iEnt = Elementary ;
-	      Tree_Insert(c->Simplexes, &simp) ;
-	      Tree_Insert(M->Simplexes, &simp) ; 
+	      //simp = Create_Simplex(vertsp[0], vertsp[1], NULL , NULL);
+	      //simp->Num = Num ;
+	      //simp->iEnt = Elementary ;
+	      //Tree_Insert(c->Simplexes, &simp) ;
+	      //Tree_Insert(M->Simplexes, &simp) ; 
 	      break;
 	    case TRI1:
 	      simp = Create_Simplex(vertsp[0], vertsp[1], vertsp[2], NULL);
-- 
GitLab