From 629fe7b44248ec831ffdad0f74061c8219224e14 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 22 Jan 2003 04:08:49 +0000
Subject: [PATCH] Fixed very small memory leak (should not leak any byte
 anymore, according to memprof!)

---
 Graphics/gl2ps.cpp | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/Graphics/gl2ps.cpp b/Graphics/gl2ps.cpp
index 39b1b862a0..d60188361c 100644
--- a/Graphics/gl2ps.cpp
+++ b/Graphics/gl2ps.cpp
@@ -2,7 +2,7 @@
  * GL2PS, an OpenGL to PostScript Printing Library
  * Copyright (C) 1999-2002  Christophe Geuzaine 
  *
- * $Id: gl2ps.cpp,v 1.56 2003-01-22 02:35:47 geuzaine Exp $
+ * $Id: gl2ps.cpp,v 1.57 2003-01-22 04:08:49 geuzaine Exp $
  *
  * E-mail: geuz@geuz.org
  * URL: http://www.geuz.org/gl2ps/
@@ -515,18 +515,22 @@ void gl2psAddPrimitiveInList(GL2PSprimitive *prim, GL2PSlist *list){
   
 }
 
-void gl2psFreeBspTree(GL2PSbsptree *tree){
-  if(tree->back){
-    gl2psFreeBspTree(tree->back);
-    gl2psFree(tree->back);
-  }
-  if(tree->primitives){
-    gl2psListAction(tree->primitives, gl2psFreePrimitive);
-    gl2psListDelete(tree->primitives);
-  }
-  if(tree->front){
-    gl2psFreeBspTree(tree->front);
-    gl2psFree(tree->front);
+void gl2psFreeBspTree(GL2PSbsptree **tree){
+  if(*tree){
+    if((*tree)->back){
+      gl2psFreeBspTree(&(*tree)->back);
+      gl2psFree((*tree)->back);
+    }
+    if((*tree)->primitives){
+      gl2psListAction((*tree)->primitives, gl2psFreePrimitive);
+      gl2psListDelete((*tree)->primitives);
+    }
+    if((*tree)->front){
+      gl2psFreeBspTree(&(*tree)->front);
+      gl2psFree((*tree)->front);
+    }
+    gl2psFree(*tree);
+    *tree = NULL;
   }
 }
 
@@ -1727,7 +1731,7 @@ GL2PSDLL_API GLint gl2psEndPage(void){
       }
       gl2psTraverseBspTree(root, eye, (float)GL2PS_EPSILON, gl2psGreater, 
 			   pprim);
-      gl2psFreeBspTree(root);
+      gl2psFreeBspTree(&root);
       res = GL2PS_SUCCESS;
       break;
     default :
-- 
GitLab