Skip to content

Commit 18233e0

Browse files
committed
Fix memory leaks with string function name lookups
There's a few leaks where the string is copied for lowercasing but not released. Where possible, use the _lc functionality of zend_hash to do the lookup to avoid the leaks that currently exist with the manual lowercasing. Closes phpGH-14390.
1 parent 89c4db9 commit 18233e0

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PHP NEWS
3232
. Fix memory leak if calling SoapServer::setObject() twice. (nielsdos)
3333
. Fix memory leak if calling SoapServer::setClass() twice. (nielsdos)
3434
. Fix reading zlib ini settings in ext-soap. (nielsdos)
35+
. Fix memory leaks with string function name lookups. (nielsdos)
3536

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

ext/soap/soap.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ PHP_METHOD(SoapServer, addFunction)
10511051
key = zend_string_tolower(Z_STR_P(tmp_function));
10521052

10531053
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1054+
zend_string_release_ex(key, false);
10541055
zend_type_error("SoapServer::addFunction(): Function \"%s\" not found", Z_STRVAL_P(tmp_function));
10551056
SOAP_SERVER_END_CODE();
10561057
RETURN_THROWS();
@@ -1069,6 +1070,7 @@ PHP_METHOD(SoapServer, addFunction)
10691070
key = zend_string_tolower(Z_STR_P(function_name));
10701071

10711072
if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
1073+
zend_string_release_ex(key, false);
10721074
zend_argument_type_error(1, "must be a valid function name, function \"%s\" not found", Z_STRVAL_P(function_name));
10731075
SOAP_SERVER_END_CODE();
10741076
RETURN_THROWS();
@@ -1395,8 +1397,7 @@ PHP_METHOD(SoapServer, handle)
13951397
}
13961398
}
13971399
#endif
1398-
zend_string *fn_name = zend_string_tolower(Z_STR(h->function_name));
1399-
if (zend_hash_exists(function_table, fn_name) ||
1400+
if (zend_hash_find_ptr_lc(function_table, Z_STR(h->function_name)) != NULL ||
14001401
((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) &&
14011402
zend_hash_str_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
14021403
if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) {
@@ -1412,25 +1413,21 @@ PHP_METHOD(SoapServer, handle)
14121413
instanceof_function(Z_OBJCE(h->retval), soap_fault_class_entry)) {
14131414
php_output_discard();
14141415
soap_server_fault_ex(function, &h->retval, h);
1415-
zend_string_release(fn_name);
14161416
if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
14171417
goto fail;
14181418
} else if (EG(exception)) {
14191419
php_output_discard();
14201420
_soap_server_exception(service, function, ZEND_THIS);
1421-
zend_string_release(fn_name);
14221421
if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
14231422
goto fail;
14241423
}
14251424
} else if (h->mustUnderstand) {
14261425
soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL);
14271426
}
1428-
zend_string_release(fn_name);
14291427
}
14301428
}
14311429

1432-
zend_string *fn_name = zend_string_tolower(Z_STR(function_name));
1433-
if (zend_hash_exists(function_table, fn_name) ||
1430+
if (zend_hash_find_ptr_lc(function_table, Z_STR(function_name)) != NULL ||
14341431
((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) &&
14351432
zend_hash_str_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
14361433
if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) {
@@ -1452,7 +1449,6 @@ PHP_METHOD(SoapServer, handle)
14521449
} else {
14531450
php_error(E_ERROR, "Function '%s' doesn't exist", Z_STRVAL(function_name));
14541451
}
1455-
zend_string_release(fn_name);
14561452

14571453
if (EG(exception)) {
14581454
if (!zend_is_unwind_exit(EG(exception))) {

0 commit comments

Comments
 (0)