[PD-dev] fixes for two memory leaks

Ivica Ico Bukvic ico at vt.edu
Wed Mar 6 05:10:25 CET 2013


Miller, Hans, et al,

I am forwarding you two patches that are memory leaks in pd. Pd vanilla 
is affected only by one of them, while pd-extended has both (second is 
magicGlass that Hans ported from pd-l2ork and that I just figured out a 
couple days ago). Since code bases are now fairly apart on the files 
involved, I am supplying the fix in this way in hope it is easier to 
understand this way.

1) The problem that affects all versions of pd can be tested using the 
bug report on the sourceforge is related to rtext freeing:
http://sourceforge.net/tracker/?func=detail&aid=3605235&group_id=55736&atid=478070
Following implementation fixes it both for GOP abstractions and 
individual objects:

In g_graph.c glist_delete() call:

at the beginning of the function
+        t_rtext *rt = NULL;
+        int late_rtext_free = 0;

further down instad of rtext_new(x, ob);
+            rt = glist_findrtext(x, ob);
+            if (rt)
+                late_rtext_free = 1;

at the end of the function
+        if (late_rtext_free) {
+            rtext_free(rt);
+        }
      }
  }

(late_rtext_free here is to provide more clarity to the process, it is 
obviously unnecessary since you could simply check for pointer value 
instead)

2) Magicglass fix (affects pd-extended only, memory leak due to improper 
freeing of magicGlass--to test simply check memory footprint as you keep 
recreating a GOP abstraction using a variant of the patch provided on 
the sourceforge):
=========================
in g_magicglass.c (added unbind call):

void magicGlass_free(t_magicGlass *x)
{
     //fprintf(stderr,"magicglass_free\n");
+    magicGlass_unbind(x);
     x->x_dspOn = 0;
     clock_free(x->x_clearClock);
     clock_free(x->x_flashClock);
}

in g_canvas.c canvas_free function:
-    if (x->gl_magic_glass)
-      magicGlass_free(x->gl_magic_glass);
+    if (x->gl_magic_glass) {
+          //magicGlass_free(x->gl_magic_glass);
+        pd_free(&x->gl_magic_glass->x_obj.te_g.g_pd);
+    }
=========================

Best wishes,

-- 
Ivica Ico Bukvic, D.M.A
Composition, Music Technology
Director, DISIS Interactive Sound & Intermedia Studio
Director, L2Ork Linux Laptop Orchestra
Head, ICAT IMPACT Studio
Virginia Tech
Department of Music
Blacksburg, VA 24061-0240
(540) 231-6139
(540) 231-5034 (fax)
disis.music.vt.edu
l2ork.music.vt.edu
ico.bukvic.net




More information about the Pd-dev mailing list