Skip to content

Commit b39e17b

Browse files
committed
Fix memory leak in tidy output handler on error
Closes phpGH-18649.
1 parent ff2c7dc commit b39e17b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ PHP NEWS
1818
- Soap:
1919
. Fix memory leaks in php_http.c when call_user_function() fails. (nielsdos)
2020

21+
- Tidy:
22+
. Fix memory leak in tidy output handler on error. (nielsdos)
23+
2124
05 Jun 2025, PHP 8.3.22
2225

2326
- Core:

ext/tidy/tidy.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,18 +965,18 @@ static int php_tidy_output_handler(void **nothing, php_output_context *output_co
965965
TidyBuffer inbuf, outbuf, errbuf;
966966

967967
if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
968+
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
969+
php_error_docref(NULL, E_WARNING, "Input string is too long");
970+
return status;
971+
}
972+
968973
doc = tidyCreate();
969974
tidyBufInit(&errbuf);
970975

971976
if (0 == tidySetErrorBuffer(doc, &errbuf)) {
972977
tidyOptSetBool(doc, TidyForceOutput, yes);
973978
tidyOptSetBool(doc, TidyMark, no);
974979

975-
if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
976-
php_error_docref(NULL, E_WARNING, "Input string is too long");
977-
return status;
978-
}
979-
980980
TIDY_SET_DEFAULT_CONFIG(doc);
981981

982982
tidyBufInit(&inbuf);

0 commit comments

Comments
 (0)