Commits

Anonymous committed 27ce886

Modified Files:
LibXML.xs
- two potential memory leaks (within setVersion() and setEncoding())
+ setEncoding will not confuse PmmFastEncodeString() anymore

t/03doc.t
+ test case for the fixed issue (will ofcourse not fail anymore ;)

Comments (0)

Files changed (2)

 setEncoding( self, encoding )
         xmlDocPtr self
         char *encoding
+    PREINIT:
+        int charset = XML_CHAR_ENCODING_ERROR;
     CODE:
+        if ( self->encoding != NULL ) {
+            xmlFree( (xmlChar*) self->encoding );
+        }   
         self->encoding = xmlStrdup( (const xmlChar *)encoding );
+        charset = (int)xmlParseCharEncoding( (const char*)self->encoding );
+        if ( charset > 0 ) {
+            ((ProxyNodePtr)self->_private)->encoding = charset;
+        }
+        else {
+            ((ProxyNodePtr)self->_private)->encoding = XML_CHAR_ENCODING_ERROR;
+        }
+        
 
 int
 standalone( self ) 
         xmlDocPtr self
         char *version
     CODE:
+        if ( self->version != NULL ) {
+            xmlFree( (xmlChar*) self->version );
+        }
         self->version = xmlStrdup( (const xmlChar*)version );
 
 int
     
     {
         print "# document with encoding\n";
-        my $encdoc = XML::LibXML::Document->new( "1.0", "iso-8859-1" );
+        my $encdoc = XML::LibXML::Document->new( "1.0" );
+        $encdoc->setEncoding( "iso-8859-1" );
         {
             my $node = $encdoc->createElement( "foo" );
             ok($node);