From fe3c2be362dc18000970541c6199fcf1e5fbb276 Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Thu, 16 Feb 2012 21:11:23 -0500
Subject: [PATCH] implemented free() calls as part of the pd_quit() call from
 the following sourceforge bugtracker:
 http://sourceforge.net/tracker/index.php?func=detail&aid=1502860&group_id=55736&atid=478072

---
 src/g_editor.c | 16 ++++++++++++++++
 src/s_inter.c  |  6 ++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/g_editor.c b/src/g_editor.c
index 046906793..df59c3923 100644
--- a/src/g_editor.c
+++ b/src/g_editor.c
@@ -3346,6 +3346,19 @@ static t_glist *glist_finddirty(t_glist *x)
     return (0);
 }
 
+void canvas_menuclose(t_canvas *x, t_floatarg fforce);
+/* properly close all open root canvases */
+void glob_closeall(void*dummy, t_floatarg fforce)
+{
+  t_canvas*x, *y;
+  for (x = canvas_list; x; )
+    {
+      y=x->gl_next;
+      canvas_menuclose(x, fforce); /* forced closing of this root canvas */
+      x=y;
+    }
+}
+
     /* quit, after calling glist_finddirty() on all toplevels and verifying
     the user really wants to discard changes  */
 void glob_verifyquit(void *dummy, t_floatarg f)
@@ -3579,6 +3592,9 @@ static void canvas_find_parent(t_canvas *x)
 {
     if (x->gl_owner)
         canvas_vis(glist_getcanvas(x->gl_owner), 1);
+	else {
+		sys_gui("menu_raise_console;\n");
+	}
 }
 
 static int glist_dofinderror(t_glist *gl, void *error_object)
diff --git a/src/s_inter.c b/src/s_inter.c
index d9c83cffe..6cd666aaf 100644
--- a/src/s_inter.c
+++ b/src/s_inter.c
@@ -1311,8 +1311,9 @@ void sys_bail(int n)
     else _exit(1);
 }
 
-extern t_pd *garray_arraytemplatecanvas;
-extern t_pd *garray_floattemplatecanvas;
+//extern t_pd *garray_arraytemplatecanvas;
+//extern t_pd *garray_floattemplatecanvas;
+extern void glob_closeall(void *dummy, t_floatarg fforce);
 
 void glob_quit(void *dummy)
 {
@@ -1323,6 +1324,7 @@ void glob_quit(void *dummy)
 	//let's try to cleanly remove invisible template canvases
 	//if (garray_arraytemplatecanvas) canvas_free( (t_canvas *)garray_arraytemplatecanvas);
 	//if (garray_floattemplatecanvas) canvas_free( (t_canvas *)garray_floattemplatecanvas);
+	glob_closeall(0, 1);
     sys_vgui("exit\n");
     if (!sys_nogui)
     {
-- 
GitLab