From: Sandro Santilli Date: Wed, 1 Oct 2014 13:26:53 +0000 (+0000) Subject: Remove memory leaks from TWKB unit tester X-Git-Tag: 2.2.0rc1~821 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62308c113937b8f11a0f710eda85357f635266a0;p=postgis Remove memory leaks from TWKB unit tester git-svn-id: http://svn.osgeo.org/postgis/trunk@13020 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_out_twkb.c b/liblwgeom/cunit/cu_out_twkb.c index c2d611bce..359896072 100644 --- a/liblwgeom/cunit/cu_out_twkb.c +++ b/liblwgeom/cunit/cu_out_twkb.c @@ -19,13 +19,9 @@ #include "cu_tester.h" /* -** Global variable to hold TWKB strings +** Global variable to hold hex TWKB strings */ -uint8_t *s; -/* -** Global variable to hold length of TWKB-string -*/ -size_t size; +char *s; /* ** The suite initialization function. @@ -55,56 +51,59 @@ static int clean_twkb_out_suite(void) static void cu_twkb(char *wkt,int8_t prec, int64_t id) { LWGEOM *g = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE); - if ( s ) free(s); - s = (uint8_t*)lwgeom_to_twkb(g, TWKB_ID, &size,prec, id); + size_t size; + uint8_t *twkb = lwgeom_to_twkb(g, TWKB_ID, &size, prec, id); lwgeom_free(g); + if ( s ) free(s); + s = hexbytes_from_bytes(twkb, size); + free(twkb); } static void test_twkb_out_point(void) { cu_twkb("POINT(0 0 0 0)",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"01810200000000"); -// printf("TWKB: %s\n",hexbytes_from_bytes(s,size)); + CU_ASSERT_STRING_EQUAL(s,"01810200000000"); +// printf("TWKB: %s\n",s); cu_twkb("SRID=4;POINTM(1 1 1)",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"016102020202"); -// printf("TWKB: %s\n",hexbytes_from_bytes(s,size)); + CU_ASSERT_STRING_EQUAL(s,"016102020202"); +// printf("TWKB: %s\n",s); } static void test_twkb_out_linestring(void) { cu_twkb("LINESTRING(0 0,1 1)",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"0142020200000202"); -// printf("TWKB: %s\n",hexbytes_from_bytes(s,size)); + CU_ASSERT_STRING_EQUAL(s,"0142020200000202"); +// printf("TWKB: %s\n",s); cu_twkb("LINESTRING(0 0 1,1 1 2,2 2 3)",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"01620203000002020202020202"); + CU_ASSERT_STRING_EQUAL(s,"01620203000002020202020202"); cu_twkb("LINESTRING EMPTY",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"0101024200"); + CU_ASSERT_STRING_EQUAL(s,"0101024200"); } static void test_twkb_out_polygon(void) { cu_twkb("SRID=4;POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0))",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"0163020105000000000200020000000100010000"); + CU_ASSERT_STRING_EQUAL(s,"0163020105000000000200020000000100010000"); cu_twkb("SRID=14;POLYGON((0 0 0 1,0 1 0 2,1 1 0 3,1 0 0 4,0 0 0 5))",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"01830201050000000200020002020000020001000201000002"); + CU_ASSERT_STRING_EQUAL(s,"01830201050000000200020002020000020001000201000002"); cu_twkb("POLYGON EMPTY",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"0101024300"); + CU_ASSERT_STRING_EQUAL(s,"0101024300"); } static void test_twkb_out_multipoint(void) { cu_twkb("SRID=4;MULTIPOINT(0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"01640205000000000200020000000100010000"); + CU_ASSERT_STRING_EQUAL(s,"01640205000000000200020000000100010000"); cu_twkb("MULTIPOINT(0 0 0, 0.26794919243112270647255365849413 1 3)",7,1); //printf("WKB: %s",s); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"71640202000000888BC70280DAC409808ECE1C"); -// printf("TWKB: %s\n",hexbytes_from_bytes(s,size)); + CU_ASSERT_STRING_EQUAL(s,"71640202000000888BC70280DAC409808ECE1C"); +// printf("TWKB: %s\n",s); } static void test_twkb_out_multilinestring(void) {} @@ -112,16 +111,16 @@ static void test_twkb_out_multilinestring(void) {} static void test_twkb_out_multipolygon(void) { cu_twkb("SRID=14;MULTIPOLYGON(((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((-1 -1 0,-1 2 0,2 2 0,2 -1 0,-1 -1 0),(0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)))",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"016602020105000000000200020000000100010000020501010000060006000000050005000005020200000200020000000100010000"); + CU_ASSERT_STRING_EQUAL(s,"016602020105000000000200020000000100010000020501010000060006000000050005000005020200000200020000000100010000"); } static void test_twkb_out_collection(void) { cu_twkb("SRID=14;GEOMETRYCOLLECTION(POLYGON((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),POINT(1 1 1))",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"0167020263010500000000020002000000010001000061020202"); + CU_ASSERT_STRING_EQUAL(s,"0167020263010500000000020002000000010001000061020202"); cu_twkb("GEOMETRYCOLLECTION EMPTY",0,1); - CU_ASSERT_STRING_EQUAL(hexbytes_from_bytes(s,size),"0101024700"); + CU_ASSERT_STRING_EQUAL(s,"0101024700"); }