From 0dd86983bb669b0f958db9075c878521b3e830a7 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 5 Nov 2024 09:26:16 +0100 Subject: [PATCH] fix(dav): Reduce memory usage while reading CardDAV cards Signed-off-by: Christoph Wurst --- apps/dav/lib/CardDAV/CardDavBackend.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index f7d0a888efd..b44fd37f488 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -519,6 +519,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $result = $query->executeQuery(); $row = $result->fetch(); if (!$row) { + $result->closeCursor(); return false; } $row['etag'] = '"' . $row['etag'] . '"'; @@ -528,6 +529,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { if ($modified) { $row['size'] = strlen($row['carddata']); } + $result->closeCursor(); return $row; } @@ -974,7 +976,12 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ private function readBlob($cardData, &$modified = false) { if (is_resource($cardData)) { - $cardData = stream_get_contents($cardData); + $stringCardData = stream_get_contents($cardData); + if ($stringCardData === false) { + return ''; + } + fclose($cardData); + $cardData = $stringCardData; } // Micro optimisation -- 2.39.5