@@ -644,11 +644,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
644644 }
645645
646646 /* Allocate the Output buffer front-end. */
647- ret = xmlAllocOutputBuffer (encoder );
648- if (ret != NULL ) {
649- ret -> context = context ;
650- ret -> writecallback = php_libxml_streams_IO_write ;
651- ret -> closecallback = php_libxml_streams_IO_close ;
647+ ret = xmlOutputBufferCreateIO (php_libxml_streams_IO_write , php_libxml_streams_IO_close , context , encoder );
648+ if (ret == NULL ) {
649+ php_libxml_streams_IO_close (context );
650+ goto err ;
652651 }
653652
654653 return (ret );
@@ -820,6 +819,7 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
820819 zend_string_release (callable_name );
821820 zval_ptr_dtor (& callable );
822821 } else {
822+ #if LIBXML_VERSION < 21400
823823 /* TODO: allow storing the encoding in the stream context? */
824824 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE ;
825825 xmlParserInputBufferPtr pib = xmlAllocParserInputBuffer (enc );
@@ -838,6 +838,12 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
838838 xmlFreeParserInputBuffer (pib );
839839 }
840840 }
841+ #else
842+ /* make stream not being closed when the zval is freed */
843+ GC_ADDREF (stream -> res );
844+ ret = xmlNewInputFromIO (NULL , php_libxml_streams_IO_read , php_libxml_streams_IO_close , stream , 0 );
845+ /* Note: if ret == NULL, the close operation will be executed, so don't DELREF stream->res upon failure! */
846+ #endif
841847 }
842848 } else if (Z_TYPE (retval ) != IS_NULL ) {
843849 /* retval not string nor resource nor null; convert to string */
0 commit comments