Update of /cvsroot/flexml/flexml
In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv23468
Modified Files:
skel flexml.pl
Log Message:
Fix sourceforge bug #1461947: bufferstack memory leak.
This fixes both leaks of attributes and leaks of pcdata;
also add debug code in skel that prints out bufferstack.
Index: skel
===================================================================
RCS file: /cvsroot/flexml/flexml/skel,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- skel 10 Aug 2006 19:02:12 -0000 1.32
+++ skel 15 Aug 2006 16:01:13 -0000 1.33
@@ -71,9 +71,7 @@
typedef struct BufferLast_s {
struct BufferLast_s *old; const char* saved; char new1[1];
} BufferLast;
-#ifdef FLEXML_HasMixed
static BufferLast* last = (BufferLast*)0;
-#endif
static char* next = bufferstack;
#define BUFFERSET(P) (P = next)
@@ -92,7 +90,6 @@
BUFFERDONE;
}
-#ifdef FLEXML_HasMixed
static void pushbuffer(const char* p)
{
BufferLast* l = (BufferLast*)next;
@@ -111,7 +108,6 @@
next = (char*)l;
return l->saved;
}
-#endif
/* General internal entities are `unput' back onto the input stream... */
#define ENTITYTEXT(T) \
@@ -173,6 +169,14 @@
/* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
SET(PROLOG);
+ #ifdef FLEX_DEBUG
+ {
+ int i;
+ for (i = 0; i < FLEXML_BUFFERSTACKSIZE; i++) {
+ bufferstack[i] = '\377';
+ }
+ }
+ #endif
FLEXML_EXTRA_DEFINITIONS_INIT
/* COMMENTS and PIs: handled uniformly for efficiency. */
@@ -298,9 +302,23 @@
va_end(ap);
}
+void print_bufferstack()
+{
+ int i;
+ fputs("Buffer: ", stderr);
+ for (i = 0; i < FLEXML_BUFFERSTACKSIZE; i++) {
+ if ( bufferstack[i] == '\377' ) break;
+ putc(bufferstack[i], stderr);
+ }
+ putc('\n', stderr);
+}
+
static void debug_enter(int state, const char* statename) {
yy_push_state(state);
- if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
+ if (yy_flex_debug) {
+ print_yy_stack("--ENTER(%s) : ",statename);
+ print_bufferstack();
+ }
}
static void debug_leave(void) {
Index: flexml.pl
===================================================================
RCS file: /cvsroot/flexml/flexml/flexml.pl,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- flexml.pl 18 Jul 2006 19:08:58 -0000 1.54
+++ flexml.pl 15 Aug 2006 16:01:13 -0000 1.55
@@ -1215,7 +1215,6 @@
print "#define FLEXML_yylineno\n" if $lineno;
print "#define FLEXML_NOFAIL\n" if $nofail;
print "#define FLEXML_quiet_parser\n" if $quiet_parser;
- print "#define FLEXML_HasMixed\n" if %inmixed;
print "#define FLEXML_BUFFERSTACKSIZE $stacksize\n";
print "\n";
@@ -1352,7 +1351,7 @@
for my $attribute (@myattributes) {
print " A_${tagprefix}${myctag}_$catt{$attribute} = " . $initof{"$tag/$attribute"} . ";\n";
}
- print " ENTER(AL_${tagprefix}$myctag);\n";
+ print " ENTER(AL_${tagprefix}$myctag); pushbuffer(NULL);\n";
print " }\n";
# print " . FAIL(\"Unexpected character `%c': `<$tag' expected.\",yytext[0]);\n";
@@ -1426,9 +1425,9 @@
. " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n";
}
}
- print " LEAVE; STag_${tagprefix}$myctag();"
+ print " LEAVE; STag_${tagprefix}$myctag(); popbuffer(); "
. (%inmixed ? ' pushbuffer('."${tagprefix}".'pcdata);' : '')
- . ($mixed{$tag} ? 'BUFFERSET('."${tagprefix}".'pcdata)' : "${tagprefix}".'pcdata = NULL'). ";"
+ . ($mixed{$tag} ? 'pushbuffer('."${tagprefix}".'pcdata); BUFFERSET('."${tagprefix}".'pcdata);' : "${tagprefix}".'pcdata = NULL'). ";"
. " ENTER($startstate{$tag});\n";
print " }\n";
#
@@ -1441,7 +1440,7 @@
. " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n";
}
}
- print " LEAVE; STag_${tagprefix}$myctag();"
+ print " LEAVE; STag_${tagprefix}$myctag(); popbuffer();"
. (%inmixed ? ' pushbuffer('."${tagprefix}".'pcdata);' : '')
. " ${tagprefix}".'pcdata = ' . ($mixed{$tag} ? '""' : 'NULL') . ';'
. " ETag_${tagprefix}$myctag();"
@@ -1470,6 +1469,7 @@
print " LEAVE;\n";
print " BUFFERDONE;\n" if $mixed{$tag};
print " ETag_${tagprefix}$myctag();\n";
+ print " ${tagprefix}pcdata = popbuffer();\n" if $mixed{$tag};
print " ${tagprefix}pcdata = popbuffer();\n" if %inmixed;
print $exitswitch;
print " }\n";
|