]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(dav): Reduce memory usage while reading CardDAV cards fix/dav/carddav-read-card-memory-usage 49089/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 5 Nov 2024 08:26:16 +0000 (09:26 +0100)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 5 Nov 2024 08:26:16 +0000 (09:26 +0100)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
apps/dav/lib/CardDAV/CardDavBackend.php

index f7d0a888efd79d35292e45a22b816edb2de44881..b44fd37f4885c9cfaee7856aab134efe9628c7c3 100644 (file)
@@ -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