Search code examples
javamemory-leaksstringbuffer

leakage in StringBuffer.toString() casting issue


How to fix the issue of data/memory leakage in StringBuffer.toString() casting in Java. I have found some tips like using a SAX parser for XML but need some more help.

Does anyone have any alternative suggestions.

Thanks in advance

xml.append("<?xml version=\"1.0\"?>");
xml.append("<parent>");
xml.append("<child>");
xml.append("<Desc>");
xml.append(desc);
xml.append("</Desc>");
xml.append("</child>");
xml.append("</parent>");

response.getWriter().write(xml.toString());
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");

desc is the description of a field in the jsp been fetched from database.


Solution

  • just validate the desc field using ESAPI