Releasing XfoObj object properly.
authorTony Graham
Mon, 02 Dec 2013 15:42:46 +0000
changeset 18 28ef4f6455d4
parent 17 30e136c75630
child 19 d7ac27d3c5a4
Releasing XfoObj object properly.
FOPRunXSLTExt/src/org/w3c/ppl/xslt/ext/ahf/saxon/RunAHFSaxon.java
--- a/FOPRunXSLTExt/src/org/w3c/ppl/xslt/ext/ahf/saxon/RunAHFSaxon.java	Mon Dec 02 14:37:14 2013 +0000
+++ b/FOPRunXSLTExt/src/org/w3c/ppl/xslt/ext/ahf/saxon/RunAHFSaxon.java	Mon Dec 02 15:42:46 2013 +0000
@@ -66,21 +66,31 @@
                 Document foTree = (Document) DocumentOverNodeInfo.wrap(item);
                 ByteArrayInputStream isFo = null;
                 ByteArrayOutputStream osAt = null;
+                XfoObj axfo = null;
                 try {
                     isFo = new ByteArrayInputStream(nodeToString(foTree).getBytes("UTF-8"));
                     osAt = new ByteArrayOutputStream();
                     
-                    XfoObj axfo = new XfoObj();
+                    axfo = new XfoObj();
                     ErrDump eDump = new ErrDump();
                     axfo.setMessageListener(eDump);
                     axfo.setExitLevel(4);
                     axfo.render(isFo, osAt, "@AreaTree");
+                    StreamSource sAt = new StreamSource(new ByteArrayInputStream(osAt.toByteArray()));
+                    return Value.asIterator(new ObjectValue(sAt));
                 } catch (Exception ex) {
                     ex.printStackTrace();
                     throw new XPathException(ex);
                 }
-                StreamSource sAt = new StreamSource(new ByteArrayInputStream(osAt.toByteArray()));
-                return Value.asIterator(new ObjectValue(sAt));
+		finally {
+                    try {
+			if (axfo != null)
+                            axfo.releaseObjectEx();
+                    } catch (XfoException e) {
+                        System.out.println("ErrorLevel = " + e.getErrorLevel() + "\nErrorCode = " + e.getErrorCode() + "\n" + e.getErrorMessage());
+                        return null;
+                    }
+		}
             }
         };
     }