@@ -615,11 +615,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
615615 }
616616
617617 /* Allocate the Output buffer front-end. */
618- ret = xmlAllocOutputBuffer (encoder );
619- if (ret != NULL ) {
620- ret -> context = context ;
621- ret -> writecallback = php_libxml_streams_IO_write ;
622- ret -> closecallback = php_libxml_streams_IO_close ;
618+ ret = xmlOutputBufferCreateIO (php_libxml_streams_IO_write , php_libxml_streams_IO_close , context , encoder );
619+ if (ret == NULL ) {
620+ php_libxml_streams_IO_close (context );
621+ goto err ;
623622 }
624623
625624 return ret ;
@@ -806,6 +805,7 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
806805 zend_string_release (callable_name );
807806 zval_ptr_dtor (& callable );
808807 } else {
808+ #if LIBXML_VERSION < 21400
809809 /* TODO: allow storing the encoding in the stream context? */
810810 xmlCharEncoding enc = XML_CHAR_ENCODING_NONE ;
811811 xmlParserInputBufferPtr pib = xmlAllocParserInputBuffer (enc );
@@ -824,6 +824,12 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
824824 xmlFreeParserInputBuffer (pib );
825825 }
826826 }
827+ #else
828+ /* make stream not being closed when the zval is freed */
829+ GC_ADDREF (stream -> res );
830+ ret = xmlNewInputFromIO (NULL , php_libxml_streams_IO_read , php_libxml_streams_IO_close , stream , 0 );
831+ /* Note: if ret == NULL, the close operation will be executed, so don't DELREF stream->res upon failure! */
832+ #endif
827833 }
828834 } else if (Z_TYPE (retval ) != IS_NULL ) {
829835 /* retval not string nor resource nor null; convert to string */
0 commit comments