Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-05-11 14:42:15 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-05-12 15:23:41 +0300
commit93d11269c299159f1a70840ed9fec6f0aaa32471 (patch)
tree52b7cb3bf4a3e3bde87228c581efbeef52a7b5c7 /lib
parentb4d772336a51c4898fd9e9ad937ed179e90d39c1 (diff)
Fix memory leak when accessing Horde headers
Horde offers access to headers either unparsed, as stream or parsed into an object. Before the patch we used the latter. That has the current bug that it opens a PHP memory stream, parses into an object but leaves the stream open. If this is done thousands of times, there is a considerate amount of memory that doesn't get freed. With the patch we request just the stream, trigger the parsing ourselves and close the stream afterwards. This frees the memory. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/Model/IMAPMessage.php21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/Model/IMAPMessage.php b/lib/Model/IMAPMessage.php
index 0b3c38f50..67dac0237 100644
--- a/lib/Model/IMAPMessage.php
+++ b/lib/Model/IMAPMessage.php
@@ -52,6 +52,7 @@ use OCA\Mail\Service\Html;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\File;
use OCP\Files\SimpleFS\ISimpleFile;
+use function fclose;
use function in_array;
use function mb_convert_encoding;
use function mb_strcut;
@@ -179,13 +180,15 @@ class IMAPMessage implements IMessage, JsonSerializable {
}
private function getRawReferences(): string {
- /** @var Horde_Mime_Headers $headers */
- $headers = $this->fetch->getHeaderText('0', Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
- $header = $headers->getHeader('references');
- if ($header === null) {
+ /** @var resource $headersStream */
+ $headersStream = $this->fetch->getHeaderText('0', Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
+ $parsedHeaders = Horde_Mime_Headers::parseHeaders($headersStream);
+ fclose($headersStream);
+ $references = $parsedHeaders->getHeader('references');
+ if ($references === null) {
return '';
}
- return $header->value_single;
+ return $references->value_single;
}
private function getRawInReplyTo(): string {
@@ -193,9 +196,11 @@ class IMAPMessage implements IMessage, JsonSerializable {
}
public function getDispositionNotificationTo(): string {
- /** @var Horde_Mime_Headers $headers */
- $headers = $this->fetch->getHeaderText('0', Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
- $header = $headers->getHeader('disposition-notification-to');
+ /** @var resource $headersStream */
+ $headersStream = $this->fetch->getHeaderText('0', Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
+ $parsedHeaders = Horde_Mime_Headers::parseHeaders($headersStream);
+ fclose($headersStream);
+ $header = $parsedHeaders->getHeader('disposition-notification-to');
if ($header === null) {
return '';
}