Skip to content

Commit 29afda7

Browse files
committed
Fix memory leak if calling SoapServer::setClass() twice
1 parent c815cdc commit 29afda7

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PHP NEWS
2828

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

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

ext/soap/soap.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName,
6666
static void delete_service(void *service);
6767
static void delete_url(void *handle);
6868
static void delete_hashtable(void *hashtable);
69+
static void delete_argv(struct _soap_class *class);
6970

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

@@ -930,6 +931,8 @@ PHP_METHOD(SoapServer, setClass)
930931
service->type = SOAP_CLASS;
931932
service->soap_class.ce = ce;
932933

934+
delete_argv(&service->soap_class);
935+
933936
service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
934937
service->soap_class.argc = num_args;
935938
if (service->soap_class.argc > 0) {
@@ -4342,6 +4345,16 @@ static void delete_url(void *handle) /* {{{ */
43424345
}
43434346
/* }}} */
43444347

4348+
static void delete_argv(struct _soap_class *class)
4349+
{
4350+
if (class->argc) {
4351+
for (int i = 0; i < class->argc; i++) {
4352+
zval_ptr_dtor(&class->argv[i]);
4353+
}
4354+
efree(class->argv);
4355+
}
4356+
}
4357+
43454358
static void delete_service(void *data) /* {{{ */
43464359
{
43474360
soapServicePtr service = (soapServicePtr)data;
@@ -4356,13 +4369,7 @@ static void delete_service(void *data) /* {{{ */
43564369
efree(service->typemap);
43574370
}
43584371

4359-
if (service->soap_class.argc) {
4360-
int i;
4361-
for (i = 0; i < service->soap_class.argc;i++) {
4362-
zval_ptr_dtor(&service->soap_class.argv[i]);
4363-
}
4364-
efree(service->soap_class.argv);
4365-
}
4372+
delete_argv(&service->soap_class);
43664373

43674374
if (service->actor) {
43684375
efree(service->actor);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
SOAP Server: SoapServer::setClass() twice
3+
--EXTENSIONS--
4+
soap
5+
--FILE--
6+
<?php
7+
class Foo {
8+
function test() {
9+
return "Hello World";
10+
}
11+
}
12+
13+
$server = new SoapServer(null,array('uri'=>"http://testuri.org"));
14+
$server->setClass(Foo::class, new stdClass, []);
15+
$server->setClass(Foo::class, new stdClass, []);
16+
17+
echo "Done\n";
18+
?>
19+
--EXPECT--
20+
Done

0 commit comments

Comments
 (0)