From 4537b661e12676de6b74044eaddc3909113b6ae0 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 20 Apr 2019 00:37:49 +0200 Subject: [PATCH] fix: Close playlist streams correctly --- classes/PlaylistArchiveStream.php | 12 ++++++++++++ tests/PlaylistArchiveStreamTest.php | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/classes/PlaylistArchiveStream.php b/classes/PlaylistArchiveStream.php index 8ee5d14..b050c61 100644 --- a/classes/PlaylistArchiveStream.php +++ b/classes/PlaylistArchiveStream.php @@ -208,4 +208,16 @@ class PlaylistArchiveStream extends TarArchive return fread($this->buffer, $count); } + + /** + * Called when fclose() is used on the stream. + * + * @return void + */ + public function stream_close() + { + if (is_resource($this->buffer)) { + fclose($this->buffer); + } + } } diff --git a/tests/PlaylistArchiveStreamTest.php b/tests/PlaylistArchiveStreamTest.php index fde76c6..36a49d3 100644 --- a/tests/PlaylistArchiveStreamTest.php +++ b/tests/PlaylistArchiveStreamTest.php @@ -34,6 +34,16 @@ class PlaylistArchiveStreamTest extends TestCase $this->stream = new PlaylistArchiveStream(Config::getInstance('config/'.$configFile)); } + /** + * Clean variables used in tests. + * + * @return void + */ + protected function tearDown() + { + $this->stream->stream_close(); + } + /** * Test the stream_open() function. *