Skip to content

Fix memory leak if calling SoapServer::setClass() twice #14381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PHP NEWS

- Soap:
. Fixed bug #47925 (PHPClient can't decompress response). (nielsdos)
. Fix memory leak if calling SoapServer::setClass() twice. (nielsdos)

- Sodium:
. Fix memory leaks in ext/sodium on failure of some functions. (nielsdos)
Expand Down
21 changes: 14 additions & 7 deletions ext/soap/soap.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName,
static void delete_service(void *service);
static void delete_url(void *handle);
static void delete_hashtable(void *hashtable);
static void delete_argv(struct _soap_class *class);

static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);

Expand Down Expand Up @@ -930,6 +931,8 @@ PHP_METHOD(SoapServer, setClass)
service->type = SOAP_CLASS;
service->soap_class.ce = ce;

delete_argv(&service->soap_class);

service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
service->soap_class.argc = num_args;
if (service->soap_class.argc > 0) {
Expand Down Expand Up @@ -4342,6 +4345,16 @@ static void delete_url(void *handle) /* {{{ */
}
/* }}} */

static void delete_argv(struct _soap_class *class)
{
if (class->argc) {
for (int i = 0; i < class->argc; i++) {
zval_ptr_dtor(&class->argv[i]);
}
efree(class->argv);
}
}

static void delete_service(void *data) /* {{{ */
{
soapServicePtr service = (soapServicePtr)data;
Expand All @@ -4356,13 +4369,7 @@ static void delete_service(void *data) /* {{{ */
efree(service->typemap);
}

if (service->soap_class.argc) {
int i;
for (i = 0; i < service->soap_class.argc;i++) {
zval_ptr_dtor(&service->soap_class.argv[i]);
}
efree(service->soap_class.argv);
}
delete_argv(&service->soap_class);

if (service->actor) {
efree(service->actor);
Expand Down
20 changes: 20 additions & 0 deletions ext/soap/tests/bugs/setClass_twice.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
SOAP Server: SoapServer::setClass() twice
--EXTENSIONS--
soap
--FILE--
<?php
class Foo {
function test() {
return "Hello World";
}
}

$server = new SoapServer(null,array('uri'=>"http://testuri.org"));
$server->setClass(Foo::class, new stdClass, []);
$server->setClass(Foo::class, new stdClass, []);

echo "Done\n";
?>
--EXPECT--
Done
Loading