Skip to content

Commit df219cc

Browse files
committed
ext/soap: Fix memory leaks when calling SoapFault::__construct() twice
1 parent 43bc53a commit df219cc

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ PHP NEWS
5656
. Fixed bug #69280 (SoapClient classmap doesn't support fully qualified class
5757
name). (nielsdos)
5858
. Fixed bug #76232 (SoapClient Cookie Header Semicolon). (nielsdos)
59+
. Fixed memory leaks when calling SoapFault::__construct() twice. (Girgias)
5960

6061
- Sodium:
6162
. Fix memory leaks in ext/sodium on failure of some functions. (nielsdos)

ext/soap/soap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,17 @@ PHP_METHOD(SoapHeader, __construct)
520520
}
521521
/* }}} */
522522

523+
static void soap_fault_dtor_properties(zval *obj)
524+
{
525+
zval_ptr_dtor(Z_FAULT_STRING_P(obj));
526+
zval_ptr_dtor(Z_FAULT_CODE_P(obj));
527+
zval_ptr_dtor(Z_FAULT_CODENS_P(obj));
528+
zval_ptr_dtor(Z_FAULT_ACTOR_P(obj));
529+
zval_ptr_dtor(Z_FAULT_DETAIL_P(obj));
530+
zval_ptr_dtor(Z_FAULT_NAME_P(obj));
531+
zval_ptr_dtor(Z_FAULT_HEADERFAULT_P(obj));
532+
}
533+
523534
/* {{{ SoapFault constructor */
524535
PHP_METHOD(SoapFault, __construct)
525536
{
@@ -539,6 +550,9 @@ PHP_METHOD(SoapFault, __construct)
539550
Z_PARAM_ZVAL_OR_NULL(headerfault)
540551
ZEND_PARSE_PARAMETERS_END();
541552

553+
/* Delete previously set properties */
554+
soap_fault_dtor_properties(ZEND_THIS);
555+
542556
if (code_str) {
543557
fault_code = ZSTR_VAL(code_str);
544558
fault_code_len = ZSTR_LEN(code_str);

ext/soap/tests/SoapFault/gh14586.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-14586: SoapFault::__construct() leaks memory if called twice
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
$sf = new SoapFault(null, "x");
8+
$sf->__construct(null, "x");
9+
?>
10+
DONE
11+
--EXPECT--
12+
DONE

0 commit comments

Comments
 (0)