LP#1845050: fix issue where reports interface was partially loaded
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 24 Sep 2019 17:48:08 +0000 (13:48 -0400)
committerJason Boyer <jboyer@equinoxinitiative.org>
Tue, 1 Oct 2019 21:04:29 +0000 (17:04 -0400)
This patch adjusts mod_xmlent to not free its XML parser
prematurely in the face of an EOS bucket received while processing
a sub-request.

To test
-------
[1] Test on a platform that has Apache 2.4.25 or later, such as
    Debian Stretch.
[2] Note that when loading the reports interface that the source
    of the frame containing oils_rpt.xhtml is incomplete and that
    actions like creating a template or folder do not work in the
    interface.
[3] Apply the patch and repeat step 2. This time, oils_rpt.xhtml
    should be fully loaded and the interface fuctional.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jason Boyer <jboyer@equinoxinitiative.org>
Open-ILS/src/apachemods/mod_xmlent.c

index d1a88ad..1a57e82 100644 (file)
@@ -323,6 +323,8 @@ static int xmlEntHandler( ap_filter_t *f, apr_bucket_brigade *brigade ) {
        if( parser == NULL ) {
                firstrun = 1;
                parser = XML_ParserCreate("UTF-8");
+               ap_log_rerror( APLOG_MARK, APLOG_DEBUG, 0, f->r,
+                               "XMLENT: created XML parser");
                XML_SetUserData(parser, f);
                XML_SetElementHandler(parser, startElement, endElement);
                XML_SetCharacterDataHandler(parser, charHandler);
@@ -364,8 +366,16 @@ static int xmlEntHandler( ap_filter_t *f, apr_bucket_brigade *brigade ) {
                APR_BUCKET_REMOVE(currentBucket);
                        APR_BRIGADE_INSERT_TAIL(ctx->brigade, currentBucket);
                        ap_pass_brigade(f->next, ctx->brigade);
-                       XML_ParserFree(parser);
-                       parser = NULL;
+                       if (f->r->main == NULL) {
+                               // free the XML parser only if we've seen the end
+                               // for the main request; we'll keep it around if
+                               // the EOS was for a sub-request, as we may get
+                               // more to process.
+                               XML_ParserFree(parser);
+                               parser = NULL;
+                               ap_log_rerror( APLOG_MARK, APLOG_DEBUG, 0, f->r,
+                                       "XMLENT: freed XML parser");
+                       }
                        return APR_SUCCESS;
        }