diff --git a/tests/Makefile b/tests/Makefile index 6ebd127..5dc1a23 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -36,7 +36,7 @@ PROGS = test1 test2 test3 test4 test5 test6 test7 test8 \ test97 test98 test99 test100 test101 test102 test103 test104 \ test105 test106 test107 test108 test109 test110 test111 test112 \ test113 test114 test115 test116 test117 test118 test119 test120 \ - test121 test122 test123 test124 + test121 test122 test123 test124 test125 TPLSRC = ../src CFLAGS = -I$(TPLSRC) -g diff --git a/tests/README b/tests/README index eef1f17..856ff46 100644 --- a/tests/README +++ b/tests/README @@ -123,3 +123,4 @@ test121: test s## test122: test S(ic#f$(ci)) test123: setjmp/longjmp based fatal error handler test124: test A(S(c#)s) as per bug report from Eric Rose +test125: test to manifest a free bug with S(s)# per Andrei Diaconu diff --git a/tests/test125.c b/tests/test125.c new file mode 100644 index 0000000..5f3e0ac --- /dev/null +++ b/tests/test125.c @@ -0,0 +1,27 @@ +#include "tpl.h" + +struct Test { + char *string; +}; + +struct Test tests[] = {{"first"}, {"second"},{"third"}}; +char buffer[5000]; /* this doesn't matter- just a place to dump to */ + +/* this test is useful under valgrind to detect an unfreed string bug +*/ + +int main(int argc, char *argv[]) { + tpl_node *tn; + tn = tpl_map("S(s)#", &tests, 3); + tpl_pack(tn, 0); + tpl_dump(tn, TPL_MEM|TPL_PREALLOCD, buffer, sizeof(buffer)); + /* at the next line, when the tpl tree is freed, the string node + * is followed by a pound node. The string node has actually had + * its data member multipled by the pound node's factor, but we + * don't know that, until after we freed the string node at tpl.c:710. + * if you run this example under valgrind --leak-check=full you can + * see 13 bytes lost which are "second" and "third" above + */ + tpl_free(tn); + return 0; +}