Skip to content

Commit 20b11b8

Browse files
authored
Merge pull request #20494 from nextcloud/backport/20361/stable17
[stable17] Close the streams in `writeStream` even when there is an exception
2 parents 14b1772 + f72a445 commit 20b11b8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/private/Files/Storage/Common.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,12 @@ public function writeStream(string $path, $stream, int $size = null): int {
853853
if (!$target) {
854854
return 0;
855855
}
856-
list($count, $result) = \OC_Helper::streamCopy($stream, $target);
857-
fclose($stream);
858-
fclose($target);
856+
try {
857+
[$count, $result] = \OC_Helper::streamCopy($stream, $target);
858+
} finally {
859+
fclose($target);
860+
fclose($stream);
861+
}
859862
return $count;
860863
}
861864
}

0 commit comments

Comments
 (0)