Skip to content

Commit ed46a95

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

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/soap/soap.c

+14
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

+12
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)