Commits

Anonymous committed f511828

Modified Files:
LibXML.xs
now frees unused strings allocated by the module (thanks to Andrew Kreiling who sent me a patch for some of the leaks)

dom.c dom.h
+ updated the interface

  • Participants
  • Parent commits aa74591

Comments (0)

Files changed (3)

     CODE:
         tstr =  domEncodeString( encoding, string );
         RETVAL = newSVpvn( (char *)tstr, xmlStrlen( tstr ) );
+        xmlFree( tstr ); 
     OUTPUT:
         RETVAL
 
     CODE: 
         tstr =  domDecodeString( encoding, string );
         RETVAL = newSVpvn( (char *)tstr, xmlStrlen( tstr ) );
+        xmlFree( tstr ); 
     OUTPUT:
         RETVAL
 
         XML::LibXML::Node::nodeName = 1
         XML::LibXML::Attr::name     = 2
     PREINIT:
-        const char * name;
+        char * name;
     CODE:
         if( node != NULL ) {
             name =  domName( node );
             RETVAL = newSVpvn( (char *)name, xmlStrlen( name ) );
+            xmlFree( name );
         }
         else {
             RETVAL = &PL_sv_undef;
         XML::LibXML::Attr::getValue  = 3
     PREINIT:
         xmlNodePtr node;
-        const char * content;
+        char * content;
     CODE:
         node = (xmlNodePtr) proxy_node->object; 
 
                                                node->content );
                 }
                 else {
-                    content = node->content;
+                    content = xmlStrdup(node->content);
                 }
             }
             else if ( node->children != NULL ) {
                                                node->children->content );
                 }
                 else {
-                    content = node->children->content;
+                    content = xmlStrdup(node->children->content);
                 }
             }
         }
 
-        if ( content != 0 ){
+        if ( content != NULL ){
             RETVAL = newSVpvn( (char *)content, xmlStrlen( content ) );
+            xmlFree( content );
         }
         else {
             RETVAL = &PL_sv_undef;
         }
         
         if ( self->doc != NULL ) {
-            ret= domDecodeString( self->doc->encoding, ret );
+            xmlChar *retDecoded = domDecodeString( self->doc->encoding, ret );
+            xmlFree( ret );
+            ret= retDecoded;
         }
 
         if ( ret != NULL ) {
-            RETVAL = newSVpvn( ret , strlen( ret ) ) ;  
+            RETVAL = newSVpvn( ret , strlen( ret ) ) ;
+            xmlFree( ret );  
         }
         else {
 	        # warn("Failed to convert doc to string");           
     ALIAS:
         XML::LibXML::Node::localname = 1
     PREINIT:
-        const char * lname;
+        char * lname;
     CODE:
         if( node != NULL ) {
             if ( node->doc != NULL ) {
                 lname = domDecodeString( node->doc->encoding, node->name );
             }
             else {
-                lname =  node->name;
+                lname = xmlStrdup( node->name );
             }
             RETVAL = newSVpvn( (char *)lname, xmlStrlen( lname ) );
+            xmlFree( lname );
         }
         else {
             RETVAL = &PL_sv_undef;
     ALIAS:
         XML::LibXML::Node::prefix = 1
     PREINIT:
-        const char * prefix;
+        char * prefix;
     CODE:
         if( node != NULL 
             && node->ns != NULL
                                           node->ns->prefix );
             }
             else {
-                prefix =  node->ns->prefix;
+                prefix =  xmlStrdup( node->ns->prefix );
             }
 
             RETVAL = newSVpvn( (char *)prefix, xmlStrlen( prefix ) );
+            xmlFree( prefix );
         }
         else {
             RETVAL = &PL_sv_undef;
 	    char * content = NULL;
     CODE:
         content = xmlGetProp( elem->object, name );
-        if ( ((xmlNodePtr)elem->object)->doc != NULL ){
-            content = domDecodeString( ((xmlNodePtr)elem->object)->doc->encoding, content );
-        }
+        if ( content != NULL ) {
+            if ( ((xmlNodePtr)elem->object)->doc != NULL ){
+                xmlChar* deccontent = domDecodeString( ((xmlNodePtr)elem->object)->doc->encoding, content );
+               xmlFree( content);
+               content = deccontent;
+            }
 
-        if ( content != NULL ) {
             RETVAL  = newSVpvn( content, xmlStrlen( content ) );
+            xmlFree( content );
         }
         else {
             RETVAL = &PL_sv_undef;
     CODE:
         att = domHasNsProp( elem->object, name, nsURI );
         if ( att != NULL && att->children != NULL ) {
-            content = att->children->content;
+            content = xmlStrdup( att->children->content ); 
         }
+        if ( content != NULL ) {
+            if ( ((xmlNodePtr)elem->object)->doc != NULL ){
+                xmlChar *deccontent = domDecodeString( ((xmlNodePtr)elem->object)->doc->encoding, content );
+                xmlFree( content );
+                content = deccontent;
+            }
 
-        if ( ((xmlNodePtr)elem->object)->doc != NULL ){
-            content = domDecodeString( ((xmlNodePtr)elem->object)->doc->encoding, content );
-        }
-
-        if ( content != NULL ) {
             RETVAL  = newSVpvn( content, xmlStrlen( content ) );
+            xmlFree( content );
         }
         else {
             RETVAL = &PL_sv_undef;
         if ( rv != NULL ) {
             xmlAddChildList( self , rv );
         }	
+        if( chunk != NULL )
+            xmlFree( chunk );
 
 void 
 appendTextNode( self, xmlString )
         xmlNodePtr self
         char * childname
         char * xmlString
+    PREINIT:
+        xmlChar * encname = NULL;
+        xmlChar * enccontent= NULL;
     CODE:
         if( self->doc != NULL ) {
             childname = domEncodeString( self->doc->encoding, childname );
         }
         xmlNewTextChild( self, NULL, childname, xmlString );
 
+
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::Text
 
 void
  * If the node belongs to a namespace it returns the prefix and 
  * the local name. otherwise only the local name is returned.
  **/
-const xmlChar*
+xmlChar*
 domName(xmlNodePtr node) {
   xmlChar *qname = NULL; 
   if ( node ) {
 
 /* A.1 DOM specified section */
 
-const xmlChar *
+xmlChar *
 domName( xmlNodePtr node );
 
 void