From: erg Date: Thu, 26 Jun 2008 20:44:57 +0000 (+0000) Subject: Fix embarrassing memory bug. X-Git-Tag: LAST_LIBGRAPH~32^2~3917 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=570c5a5eb8be548cf10a4cf78fb87686a2c2ae1f;p=graphviz Fix embarrassing memory bug. --- diff --git a/lib/xdot/xdot.c b/lib/xdot/xdot.c index 88bf16573..7eddc9f90 100755 --- a/lib/xdot/xdot.c +++ b/lib/xdot/xdot.c @@ -310,6 +310,7 @@ parseXDotF (char* s, drawfunc_t fns[], int sz) ops = (char*)gmalloc(XDBSIZE*sz); x->cnt = 0; + x->sz = sz; while ((s = parseOp (&op, s, fns))) { if (x->cnt == bufsz) { bufsz += XDBSIZE; @@ -324,7 +325,6 @@ parseXDotF (char* s, drawfunc_t fns[], int sz) free (x); x = 0; } - free (x); return x; } @@ -474,8 +474,11 @@ static void _printXDot (xdot* x, pf print, void* info) { int i; + xdot_op* op; + char* base = (char*)(x->ops); for (i = 0; i < x->cnt; i++) { - printXDot_Op (x->ops+i, print, info); + op = (xdot_op*)(base + i*x->sz); + printXDot_Op (op, print, info); if (i < x->cnt-1) print (" ", info); } } @@ -614,8 +617,13 @@ void freeXDot (xdot* x) { int i; - for (i = 0; i < x->cnt; i++) freeXOpData (x->ops+i); - free (x->ops); + xdot_op* op; + char* base = (char*)(x->ops); + for (i = 0; i < x->cnt; i++) { + op = (xdot_op*)(base + i*x->sz); + freeXOpData (op); + } + free (base); free (x); } diff --git a/lib/xdot/xdot.h b/lib/xdot/xdot.h index 3ce24cbcc..9350da8df 100755 --- a/lib/xdot/xdot.h +++ b/lib/xdot/xdot.h @@ -92,6 +92,7 @@ struct _xdot_op { typedef struct { int cnt; + int sz; xdot_op* ops; } xdot;