From 911330e62c7eb3124c137240315a70229d1471cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Fri, 24 Feb 2012 22:56:21 +0000 Subject: [PATCH] - Better fix for #61115. - Fixed resource leak in stream_socket_client(). --- ext/standard/streamsfuncs.c | 4 ---- main/streams/streams.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index c903c57594..86e0bc6e60 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -106,10 +106,6 @@ PHP_FUNCTION(stream_socket_client) context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); - if (context) { - zend_list_addref(context->rsrc_id); - } - if (flags & PHP_STREAM_CLIENT_PERSISTENT) { spprintf(&hashkey, 0, "stream_socket_client__%s", host); } diff --git a/main/streams/streams.c b/main/streams/streams.c index 2ee6083647..d8bb9d3c7a 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -366,9 +366,14 @@ PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* int ret = 1; int preserve_handle = close_options & PHP_STREAM_FREE_PRESERVE_HANDLE ? 1 : 0; int release_cast = 1; - /* on an unclean shutdown, the context may have already been freed (if it - * was created after the stream resource), so don't reference it */ - php_stream_context *context = CG(unclean_shutdown) ? NULL : stream->context; + php_stream_context *context = NULL; + + /* on an resource list destruction, the context, another resource, may have + * already been freed (if it was created after the stream resource), so + * don't reference it */ + if (!(close_options & PHP_STREAM_FREE_RSRC_DTOR)) { + context = stream->context; + } if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { preserve_handle = 1; -- 2.40.0