Commits

Anonymous committed 8fee007

Modified Files:
perl-libxml-mm.c LibXML.xs
+ fixing segfault with the latest buffer handling.
assure that the correct copy and buffer functions are used during
decoding

Comments (0)

Files changed (2)

         int format
     PREINIT:
         xmlBufferPtr buffer;
-        xmlChar *ret = NULL;
+        const xmlChar *ret = NULL;
         SV* internalFlag = NULL;
         int oldTagFlag = xmlSaveNoEmptyTags;
     CODE:
             xmlIndentTreeOutput = t_indent_var;
         }
 
-        if ( buffer->content != 0 ) {
-            ret= xmlStrdup( buffer->content );
+        if ( xmlBufferLength(buffer) > 0 ) {
+            ret = xmlBufferContent( buffer );
         }
         
-        xmlBufferFree( buffer );
         xmlSaveNoEmptyTags = oldTagFlag;
 
         if ( ret != NULL ) {
             if ( useDomEncoding!= &PL_sv_undef && SvTRUE(useDomEncoding) ) {
-                RETVAL = nodeC2Sv(ret, PmmNODE(PmmPROXYNODE(self))) ;
+                RETVAL = nodeC2Sv((xmlChar*)ret, PmmNODE(PmmPROXYNODE(self))) ;
             }
             else {
-                RETVAL = C2Sv(ret, NULL) ;
-            }
-            xmlFree( ret );
+                RETVAL = C2Sv((xmlChar*)ret, NULL) ;
+            }        
+            xmlBufferFree( buffer );
         }
         else {
+            xmlBufferFree( buffer );
 	        xs_warn("Failed to convert doc to string");           
             XSRETURN_UNDEF;
         }
     }
 
     if ( charset > 1 ) {
-        /* warn( "use document encoding %s", encoding ); */
         coder= xmlGetCharEncodingHandler( charset );
     }
     else if ( charset == XML_CHAR_ENCODING_ERROR ){
-        /* warn("no standard encoding\n"); */
         coder = xmlFindCharEncodingHandler( (const char *) encoding );
     }
     else {
         
         xmlBufferCat( in, string );        
         if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) {
-            retval = xmlStrdup(out->content);
+            retval = xmlCharStrndup(xmlBufferContent(out), xmlBufferLength(out));
         }
         else {
             xs_warn("decoding error \n");
 PmmDecodeString( const char *encoding, const xmlChar *string){
     char *ret=NULL;
     xmlCharEncoding enc;
-    xmlBufferPtr in = NULL, out = NULL;
     xmlCharEncodingHandlerPtr coder = NULL;
 
     if ( string != NULL ) {