From 06044a0816defc15c92402f26e96da7929731d78 Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Thu, 28 Feb 2013 14:11:29 -0500 Subject: [PATCH] refinements to the memory leak fix that avoid tripping consistency check in the findrtext --- pd/src/g_graph.c | 19 +++++++------------ pd/src/g_rtext.c | 12 ++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pd/src/g_graph.c b/pd/src/g_graph.c index a995e5f57..9c67bd79d 100644 --- a/pd/src/g_graph.c +++ b/pd/src/g_graph.c @@ -81,6 +81,10 @@ int canvas_setdeleting(t_canvas *x, int flag) /* JMZ: emit a closebang message */ void canvas_closebang(t_canvas *x); +/* variant of the glist_findrtext found in g_rtext.c + that does not throw a consistency check */ +extern t_rtext *glist_tryfindrtext(t_glist *gl, t_text *who); + /* delete an object from a glist and free it */ void glist_delete(t_glist *x, t_gobj *y) { @@ -142,18 +146,9 @@ void glist_delete(t_glist *x, t_gobj *y) gobj_vis(y, x, 0); if (x->gl_editor && (ob = pd_checkobject(&y->g_pd))) { //rtext_new(x, ob); - rt = glist_findrtext(x, ob); - if (rt) { - if (pd_class(&y->g_pd) != canvas_class) { - //fprintf(stderr,"glist_delete calls rtext_free %lx %d %d %d\n", - //glist_findrtext(x, ob), - //(pd_class(&y->g_pd) != canvas_class ? 1 : 0), - //(!x->gl_isgraph ? 1 : 0), - //(!x->gl_owner ? 1 : 0)); - rtext_free(rt); - } else { - late_rtext_free = 1; - } + rt = glist_tryfindrtext(x, ob); + if (rt) + late_rtext_free = 1; } } if (x->gl_list == y) { diff --git a/pd/src/g_rtext.c b/pd/src/g_rtext.c index cf8ff2bd3..f406175f0 100644 --- a/pd/src/g_rtext.c +++ b/pd/src/g_rtext.c @@ -422,6 +422,18 @@ t_rtext *glist_findrtext(t_glist *gl, t_text *who) return (x); } +/* same as above but without error reporting */ +t_rtext *glist_tryfindrtext(t_glist *gl, t_text *who) +{ + t_rtext *x=NULL; + if (!gl->gl_editor) + canvas_create_editor(gl); + if (gl->gl_editor->e_rtext) + for (x = gl->gl_editor->e_rtext; x && x->x_text != who; x = x->x_next) + ; + return (x); +} + int rtext_width(t_rtext *x) { int w = 0, h = 0, indx; -- GitLab