From d30dd1b47b023ffa98b2f2b62a6f209f64822c32 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:45:46 +0200 Subject: [PATCH] Fix GH-19784: SoapServer memory leak Closes GH-19818. --- NEWS | 3 +++ ext/soap/soap.c | 8 +++++++- ext/soap/tests/bugs/gh19784.phpt | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/soap/tests/bugs/gh19784.phpt diff --git a/NEWS b/NEWS index 04bd8789f30b3..3572f95178465 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,9 @@ PHP NEWS . Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead of the curl_copy_handle() function to clone a CurlHandle. (timwolla) +- Soap: + . Fixed bug GH-19784 (SoapServer memory leak). (nielsdos) + - Standard: . Fixed bug GH-12265 (Cloning an object breaks serialization recursion). (nielsdos) diff --git a/ext/soap/soap.c b/ext/soap/soap.c index fc51e32658f3a..4a4fa4f4e626b 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -880,7 +880,13 @@ PHP_METHOD(SoapServer, __construct) service->soap_functions.ft = zend_new_array(0); if (wsdl) { - service->sdl = get_sdl(ZEND_THIS, ZSTR_VAL(wsdl), cache_wsdl); + zend_try { + service->sdl = get_sdl(ZEND_THIS, ZSTR_VAL(wsdl), cache_wsdl); + } zend_catch { + xmlCharEncCloseFunc(service->encoding); + service->encoding = NULL; + zend_bailout(); + } zend_end_try(); if (service->uri == NULL) { if (service->sdl->target_ns) { service->uri = estrdup(service->sdl->target_ns); diff --git a/ext/soap/tests/bugs/gh19784.phpt b/ext/soap/tests/bugs/gh19784.phpt new file mode 100644 index 0000000000000..1f718e74c4598 --- /dev/null +++ b/ext/soap/tests/bugs/gh19784.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-19784 (SoapServer memory leak) +--EXTENSIONS-- +soap +--FILE-- + $v_5257); +new SoapServer('foobarbaz',$v_5238,); +?> +--EXPECTF-- + +%s%a