]> granicus.if.org Git - php/commitdiff
- Better fix for #61115.
authorGustavo André dos Santos Lopes <cataphract@php.net>
Fri, 24 Feb 2012 22:56:21 +0000 (22:56 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Fri, 24 Feb 2012 22:56:21 +0000 (22:56 +0000)
- Fixed resource leak in stream_socket_client().

ext/standard/streamsfuncs.c
main/streams/streams.c

index c903c57594892b10398dbce07bea09cbee6ad134..86e0bc6e604ef16e2c467a3628f54b9d9473d29d 100644 (file)
@@ -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);
        }
index 2ee60836470e027a5a7b36f991f4c0bbb64cf0ed..d8bb9d3c7a63da14dd3f132b43a5598f3d9854df 100755 (executable)
@@ -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;