diff options
Diffstat (limited to 'main/streams/streams.c')
-rwxr-xr-x | main/streams/streams.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c index 390db1d1ce..161430754e 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -385,7 +385,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; - php_stream_context *context = 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 (EG(active)) { + context = stream->context; + } if (stream->flags & PHP_STREAM_FLAG_NO_CLOSE) { preserve_handle = 1; @@ -464,8 +471,8 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov } /* Remove stream from any context link list */ - if (stream->context && stream->context->links) { - php_stream_context_del_link(stream->context, stream); + if (context && context->links) { + php_stream_context_del_link(context, stream); } if (close_options & PHP_STREAM_FREE_CALL_DTOR) { |