Skip to content

Commit b05c7fa

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79332: php_istreams are never freed
2 parents cb933d6 + b9843c9 commit b05c7fa

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

ext/com_dotnet/com_persist.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,6 @@ static struct IStreamVtbl php_istream_vtbl = {
247247

248248
static void istream_destructor(php_istream *stm)
249249
{
250-
if (stm->res) {
251-
zend_resource *res = stm->res;
252-
stm->res = NULL;
253-
zend_list_delete(res);
254-
return;
255-
}
256-
257250
if (stm->refcount > 0) {
258251
CoDisconnectObject((IUnknown*)stm, 0);
259252
}
@@ -267,7 +260,6 @@ static void istream_destructor(php_istream *stm)
267260
PHP_COM_DOTNET_API IStream *php_com_wrapper_export_stream(php_stream *stream)
268261
{
269262
php_istream *stm = (php_istream*)CoTaskMemAlloc(sizeof(*stm));
270-
zval *tmp;
271263

272264
if (stm == NULL)
273265
return NULL;
@@ -279,8 +271,7 @@ PHP_COM_DOTNET_API IStream *php_com_wrapper_export_stream(php_stream *stream)
279271
stm->stream = stream;
280272

281273
GC_ADDREF(stream->res);
282-
tmp = zend_list_insert(stm, le_istream);
283-
stm->res = Z_RES_P(tmp);
274+
stm->res = zend_register_resource(stm, le_istream);
284275

285276
return (IStream*)stm;
286277
}

ext/com_dotnet/tests/bug79332.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #79332 (php_istreams are never freed)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('com_dotnet extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$ph = new COMPersistHelper(null);
10+
try {
11+
$ph->LoadFromStream(fopen(__FILE__, 'r'));
12+
} catch (com_exception $ex) {
13+
// use hard-coded message to avoid localization issues
14+
echo "A com_exception has been thrown\n";
15+
}
16+
?>
17+
--EXPECT--
18+
A com_exception has been thrown

0 commit comments

Comments
 (0)