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);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.