[Gridflow-cvs] [svn] commit: r3673 - in /trunk: gridflow.c gridflow.h

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Sat Apr 26 11:54:32 EDT 2008


Author: matju
Date: Sat Apr 26 11:54:32 2008
New Revision: 3673

Log:
fixed leak of a BFProxy for each non-first inlet

Modified:
    trunk/gridflow.c
    trunk/gridflow.h

Modified: trunk/gridflow.c
==============================================================================
--- trunk/gridflow.c (original)
+++ trunk/gridflow.c Sat Apr 26 11:54:32 2008
@@ -570,8 +570,9 @@
 	bself->noutlets = 0;
 	bself->inlets  = new  BFProxy*[1];
 	bself->outlets = new t_outlet*[1];
-	bself->ninlets_set( fclasses[classsym->s_name]->ninlets);
-	bself->noutlets_set(fclasses[classsym->s_name]->noutlets);
+	bself->inlets[0] = 0; // inlet 0 of this table is not in use
+	bself->ninlets_set( fclasses[classsym->s_name]->ninlets ,false);
+	bself->noutlets_set(fclasses[classsym->s_name]->noutlets,false);
 #ifdef HAVE_GEM
 	bself->gemself = (CPPExtern *)((void **)bself->self+11); /* not 64-bit-safe */
 	CPPExtern::m_holder = 0;
@@ -594,6 +595,7 @@
 
 static void BFObject_delete (BFObject *bself) {
 	try {delete bself->self;} catch (Barf *oozy) {pd_error(bself,"%s",oozy->text);}
+	bself->ninlets_set(1,false);
 	delete[] bself->inlets;
 	delete[] bself->outlets;
 }
@@ -631,9 +633,9 @@
 }
 
 /* warning: deleting inlets that are connected will cause pd to crash */
-void BFObject::ninlets_set (int n) {
+void BFObject::ninlets_set (int n, bool draw) {
 	if (n<1) RAISE("ninlets_set: n=%d must be at least 1",n);
-	BFObject_undrawio(this);
+	if (draw) BFObject_undrawio(this);
 	if (ninlets<n) {
 		BFProxy **noo = new BFProxy*[n];
 		memcpy(noo,inlets,ninlets*sizeof(BFProxy*));
@@ -653,12 +655,12 @@
 			delete inlets[ninlets];
 		}
 	}
-	BFObject_redraw(this);
+	if (draw) BFObject_redraw(this);
 }
 /* warning: deleting outlets that are connected will cause pd to crash */
-void BFObject::noutlets_set (int n) {
+void BFObject::noutlets_set (int n, bool draw) {
 	if (n<0) RAISE("noutlets_set: n=%d must be at least 0",n);
-	BFObject_undrawio(this);
+	if (draw) BFObject_undrawio(this);
 	if (noutlets<n) {
 		t_outlet **noo = new t_outlet*[n>0?n:1];
 		memcpy(noo,outlets,noutlets*sizeof(t_outlet*));
@@ -668,7 +670,7 @@
 	} else {
 		while (noutlets>n) outlet_free(outlets[--noutlets]);
 	}
-	BFObject_redraw(this);
+	if (draw) BFObject_redraw(this);
 }
 
 void add_creator2(FClass *fclass, const char *name) {
@@ -786,6 +788,15 @@
   char **symbols = backtrace_symbols(array, nSize);
   for (int i=0; i<nSize; i++) fprintf(stderr,"%d: %s\n",i,symbols[i]);
   free(symbols);
+}
+
+// this will make valgrind happier about memory leaks
+static void gridflow_unsetup () {
+	foreach(iter,fclasses_pd) {
+		FClass *fc = iter->second;
+		foreach(iter2,fc->attrs) delete iter2->second;
+		fc->FClass::~FClass();
+	}
 }
 
 // note: contrary to what m_pd.h says, pd_getfilename() and pd_getdirname()
@@ -824,5 +835,6 @@
 	signal(SIGSEGV,SIG_DFL);
 	signal(SIGABRT,SIG_DFL);
 	signal(SIGBUS, SIG_DFL);
+	atexit(gridflow_unsetup);
     } catch (Barf *oozy) {post("Init_gridflow error: %s",oozy->text);}
 }

Modified: trunk/gridflow.h
==============================================================================
--- trunk/gridflow.h (original)
+++ trunk/gridflow.h Sat Apr 26 11:54:32 2008
@@ -833,8 +833,8 @@
 	BFProxy  **inlets;    // direct access to  inlets (not linked lists)
 	t_outlet **outlets;   // direct access to outlets (not linked lists)
 	t_canvas *mom;
-	void  ninlets_set(int n);
-	void noutlets_set(int n);
+	void  ninlets_set(int n, bool draw=true);
+	void noutlets_set(int n, bool draw=true);
 };
 
 // represents objects that have inlets/outlets



More information about the Gridflow-cvs mailing list