You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Timothy Stack <st...@cs.utah.edu> on 2004/07/15 01:12:28 UTC

[PATCH] fix for parser memory leak

hi,

At the bottom is a proposed fix for a memory leak in the XmlRpc.java
parser.  Basically, if the "cdata" StringBuffer grew to a fairly large
size, any subsequent strings returned from toString() would be backed by a
larger than necessary character array.

The first change checks the real capacity of the StringBuffer, since
length() will be zero at that point.  The other two changes are to use
substring() instead of toString() to get a String with, hopefully, a
properly sized character array...

thanks,

tim stack



Index: XmlRpc.java
===================================================================
RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpc.java,v
retrieving revision 1.37
diff -u -r1.37 XmlRpc.java
--- XmlRpc.java	30 Jun 2004 06:11:55 -0000	1.37
+++ XmlRpc.java	14 Jul 2004 22:56:35 -0000
@@ -445,7 +445,7 @@
         finally
         {
             // Clear any huge buffers.
-            if (cdata.length() > 128 * 4)
+            if (cdata.capacity() > 128 * 4)
             {
                 // Exceeded original capacity by greater than 4x; release
                 // buffer to prevent leakage.
@@ -496,8 +496,8 @@
         // finalize character data, if appropriate
         if (currentValue != null && readCdata)
         {
-            currentValue.characterData(cdata.toString());
-            cdata.setLength(0);
+            currentValue.characterData(cdata.substring(0, cdata.length()));
+	    cdata.setLength(0);
             readCdata = false;
         }
 
@@ -538,8 +538,8 @@
 
         else if ("methodName".equals(name))
         {
-            methodName = cdata.toString();
-            cdata.setLength(0);
+	    methodName = cdata.substring(0, cdata.length());
+	    cdata.setLength(0);
             readCdata = false;
         }
     }

Re: [PATCH] fix for parser memory leak

Posted by Jochen Wiedmann <jo...@freenet.de>.
Hi,

I have added your patch to my private version. See my previous mail.


Jochen