@@ -611,11 +611,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
611611 }
612612
613613 /* Allocate the Output buffer front-end. */
614- ret = xmlAllocOutputBuffer (encoder );
615- if (ret != NULL ) {
616- ret -> context = context ;
617- ret -> writecallback = php_libxml_streams_IO_write ;
618- ret -> closecallback = php_libxml_streams_IO_close ;
614+ ret = xmlOutputBufferCreateIO (php_libxml_streams_IO_write , php_libxml_streams_IO_close , context , encoder );
615+ if (ret == NULL ) {
616+ php_libxml_streams_IO_close (context );
617+ goto err ;
619618 }
620619
621620 return (ret );
@@ -802,6 +801,7 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
802801 zend_string_release (callable_name );
803802 zval_ptr_dtor (& callable );
804803 } else {
804+ #if LIBXML_VERSION < 21400
805805 /* TODO: allow storing the encoding in the stream context? */
806806 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE ;
807807 xmlParserInputBufferPtr pib = xmlAllocParserInputBuffer (enc );
@@ -820,6 +820,12 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
820820 xmlFreeParserInputBuffer (pib );
821821 }
822822 }
823+ #else
824+ /* make stream not being closed when the zval is freed */
825+ GC_ADDREF (stream -> res );
826+ ret = xmlNewInputFromIO (NULL , php_libxml_streams_IO_read , php_libxml_streams_IO_close , stream , 0 );
827+ /* Note: if ret == NULL, the close operation will be executed, so don't DELREF stream->res upon failure! */
828+ #endif
823829 }
824830 } else if (Z_TYPE (retval ) != IS_NULL ) {
825831 /* retval not string nor resource nor null; convert to string */
0 commit comments