Fix embarrassing memory bug.
authorerg <devnull@localhost>
Thu, 26 Jun 2008 20:44:57 +0000 (20:44 +0000)
committererg <devnull@localhost>
Thu, 26 Jun 2008 20:44:57 +0000 (20:44 +0000)
lib/xdot/xdot.c
lib/xdot/xdot.h

index 88bf16573f6e45fb0fc16cc93f08041ffa83fc9e..7eddc9f90dba4ed3200f5a90815ee553f099c300 100755 (executable)
@@ -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);
 }
 
index 3ce24cbcc7f935cc7fad9d81842948f88fb52f7b..9350da8df87e28d3c27de98d019f4699b17eb327 100755 (executable)
@@ -92,6 +92,7 @@ struct _xdot_op {
 
 typedef struct {
     int cnt;
+    int sz;
     xdot_op* ops;
 } xdot;