fixed a few minor mem leaks
authorMatthias Kramm <kramm@quiss.org>
Tue, 26 May 2009 22:48:40 +0000 (15:48 -0700)
committerMatthias Kramm <kramm@quiss.org>
Tue, 26 May 2009 22:48:40 +0000 (15:48 -0700)
lib/gfxpoly/convert.c
lib/gfxpoly/poly.c
lib/gfxpoly/test.c
lib/gfxtools.c
lib/q.c

index 717feba..213cdad 100644 (file)
@@ -354,6 +354,7 @@ void gfxcompactpoly_destroy(gfxcompactpoly_t*poly)
     int t;
     for(t=0;t<poly->num_strokes;t++) {
        free(poly->strokes[t].points);
+       poly->strokes[t].points = 0;
     }
     free(poly->strokes);
     free(poly);
index 9c45bdf..239cba6 100644 (file)
@@ -1277,5 +1277,7 @@ gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windconte
 
     gfxcompactpoly_t*p = (gfxcompactpoly_t*)status.writer.finish(&status.writer);
     add_horizontals(p, &windrule_evenodd, context); // output is always even/odd
-    return gfxpoly_from_gfxcompactpoly(p);
+    gfxpoly_t*pp = gfxpoly_from_gfxcompactpoly(p);
+    gfxcompactpoly_destroy(p);
+    return pp;
 }
index 4e3c875..82ceb9a 100644 (file)
@@ -114,12 +114,12 @@ gfxline_t* mkchessboard()
     return b;
 }
 
-gfxline_t* make_circles()
+gfxline_t* make_circles(int n)
 {
     gfxline_t*b = 0;
     unsigned int c = 0;
     int t;
-    for(t=0;t<30;t++) {
+    for(t=0;t<n;t++) {
         c = crc32_add_byte(c, t);
        int x = c%200;
        c = crc32_add_byte(c, t);
@@ -134,28 +134,31 @@ gfxline_t* make_circles()
 
 static windcontext_t onepolygon = {1};
 
-int test0()
+int test_speed()
 {
     //gfxline_t* b = mkchessboard();
     //gfxline_t* b = mkrandomshape(100,7);
-    gfxline_t* b = gfxline_makecircle(100,100,100,100);
+    gfxline_t* b = make_circles(30);
 
     gfxmatrix_t m;
     memset(&m, 0, sizeof(gfxmatrix_t));
     int t;
-    for(t=0;t<360;t++) {
+    for(t=0;t<10;t++) {
+       printf("%d\n", t);
        m.m00 = cos(t*M_PI/180.0);
        m.m01 = sin(t*M_PI/180.0);
        m.m10 = -sin(t*M_PI/180.0);
        m.m11 = cos(t*M_PI/180.0);
        m.tx = 400*1.41/2;
        m.ty = 400*1.41/2;
-       gfxline_transform(b, &m);
+       gfxline_t*l = gfxline_clone(b);
+       gfxline_transform(l, &m);
        gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(b, 0.05);
 
        gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
        gfxcompactpoly_destroy(poly);
        gfxpoly_destroy(poly2);
+       gfxline_free(l);
     }
     gfxline_free(b);
 }
@@ -276,7 +279,7 @@ void test3(int argn, char*argv[])
     //gfxline_t*line = mkrandomshape(RANGE, N);
     //windrule_t*rule = &windrule_circular;
     //gfxline_t*line = mkchessboard();
-    gfxline_t*line = make_circles();
+    gfxline_t*line = make_circles(30);
     windrule_t*rule = &windrule_evenodd;
     //windrule_t*rule = &windrule_circular;
 
@@ -603,6 +606,6 @@ void test5(int argn, char*argv[])
 
 int main(int argn, char*argv[])
 {
-    test4(argn, argv);
+    test_speed(argn, argv);
 }
 
index 8ee2ff4..3e565a1 100644 (file)
@@ -839,21 +839,24 @@ gfxline_t*gfxline_makecircle(double x,double y,double rx, double ry)
     double C1 = 0.2930;    
     double C2 = 0.4140;   
     double begin = 0.7070; 
-    gfxline_t* line = (gfxline_t*)rfx_calloc(sizeof(gfxline_t)*9);
+    gfxline_t** line = (gfxline_t**)rfx_calloc(sizeof(gfxline_t*)*9);
     int t;
-    line[0].type = gfx_moveTo;
-    line[0].x = x+begin*rx;
-    line[0].y = y+begin*ry;
+    for(t=0;t<9;t++) {
+       line[t] = rfx_calloc(sizeof(gfxline_t));
+    }
+    line[0]->type = gfx_moveTo;
+    line[0]->x = x+begin*rx;
+    line[0]->y = y+begin*ry;
     for(t=1;t<9;t++) {
-       line[t-1].next = &line[t];
-       line[t].type = gfx_splineTo;
+       line[t-1]->next = line[t];
+       line[t]->type = gfx_splineTo;
     }
-    line[t].next = 0;
+    line[8]->next = 0;
 #define R(nr,cx,cy,mx,my) \
-    line[nr].sx = line[nr-1].x + (cx); \
-    line[nr].sy = line[nr-1].y + (cy); \
-    line[nr].x = line[nr].sx + (mx); \
-    line[nr].y = line[nr].sy + (my);
+    line[nr]->sx = line[nr-1]->x + (cx); \
+    line[nr]->sy = line[nr-1]->y + (cy); \
+    line[nr]->x = line[nr]->sx + (mx); \
+    line[nr]->y = line[nr]->sy + (my);
     R(1, -C1*rx,  C1*ry, -C2*rx,      0);
     R(2, -C2*rx,      0, -C1*rx, -C1*ry);
     R(3, -C1*rx, -C1*ry,      0, -C2*ry);
@@ -862,7 +865,9 @@ gfxline_t*gfxline_makecircle(double x,double y,double rx, double ry)
     R(6,  C2*rx,      0,  C1*rx,  C1*ry);
     R(7,  C1*rx,  C1*ry,      0,  C2*ry);
     R(8,      0,  C2*ry, -C1*rx,  C1*ry);
-    return line;
+    gfxline_t*l = line[0];
+    free(line);
+    return l;
 }
 
 gfxbbox_t* gfxline_isrectangle(gfxline_t*_l)
diff --git a/lib/q.c b/lib/q.c
index 64934a6..1d50ca3 100644 (file)
--- a/lib/q.c
+++ b/lib/q.c
@@ -524,13 +524,14 @@ void trie_rollback(trie_t*t)
 
 
 // ------------------------------- crc32 --------------------------------------
-static unsigned int*crc32 = 0;
+static unsigned int crc32[256];
+static char crc32_initialized=0;
 static void crc32_init(void)
 {
     int t;
-    if(crc32) 
+    if(crc32_initialized) 
         return;
-    crc32= (unsigned int*)rfx_alloc(sizeof(unsigned int)*256);
+    crc32_initialized = 1;
     for(t=0; t<256; t++) {
         unsigned int c = t;
         int s;