manifest free bug in S(s)# per Andrei Diaconu

This commit is contained in:
Troy D. Hanson 2013-07-09 23:31:03 -04:00
parent 0cf16b3e8a
commit d900c940e8
3 changed files with 29 additions and 1 deletions

View File

@ -36,7 +36,7 @@ PROGS = test1 test2 test3 test4 test5 test6 test7 test8 \
test97 test98 test99 test100 test101 test102 test103 test104 \ test97 test98 test99 test100 test101 test102 test103 test104 \
test105 test106 test107 test108 test109 test110 test111 test112 \ test105 test106 test107 test108 test109 test110 test111 test112 \
test113 test114 test115 test116 test117 test118 test119 test120 \ test113 test114 test115 test116 test117 test118 test119 test120 \
test121 test122 test123 test124 test121 test122 test123 test124 test125
TPLSRC = ../src TPLSRC = ../src
CFLAGS = -I$(TPLSRC) -g CFLAGS = -I$(TPLSRC) -g

View File

@ -123,3 +123,4 @@ test121: test s##
test122: test S(ic#f$(ci)) test122: test S(ic#f$(ci))
test123: setjmp/longjmp based fatal error handler test123: setjmp/longjmp based fatal error handler
test124: test A(S(c#)s) as per bug report from Eric Rose 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

27
tests/test125.c Normal file
View File

@ -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;
}