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);
}
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;