From 5b7e27c2755d7d282a5d8153f861af169ccd8ffe Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 23 Jun 2016 14:43:46 +0200 Subject: [PATCH] reduce memmory consumption by closing stream on destruction of Sync objects containing streams --- mail/inc/class.mail_zpush.inc.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mail/inc/class.mail_zpush.inc.php b/mail/inc/class.mail_zpush.inc.php index 93a1a44bbc..7c0e4330d9 100644 --- a/mail/inc/class.mail_zpush.inc.php +++ b/mail/inc/class.mail_zpush.inc.php @@ -904,7 +904,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail, } ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType)); // set the protocoll class - $output->asbody = new SyncBaseBody(); + $output->asbody = new SyncBaseBodyCloseStream(); // return full mime-message without any (charset) conversation directly as stream if ($bpReturnType==SYNC_BODYPREFERENCE_MIME) @@ -1253,7 +1253,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail, $this->mail->reopen($folder); $attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder); - $SIOattachment = new SyncItemOperationsAttachment(); + $SIOattachment = new SyncItemOperationsAttachmentCloseStream(); fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start $SIOattachment->data = $attachment['attachment']; //ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']); @@ -2083,3 +2083,25 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail, return $dir.'/'.$dev_id.'.hashes'; } } + +/** + * Extend SyncBaseBody to close streams on destruction to free memory + */ +class SyncBaseBodyCloseStream extends SyncBaseBody +{ + function __destruct() + { + if (is_resource($this->data)) fclose($this->data); + } +} + +/** + * Extend SyncItemOperationsAttachment to close streams on destruction to free memory + */ +class SyncItemOperationsAttachmentCloseStream extends SyncItemOperationsAttachment +{ + function __destruct() + { + if (is_resource($this->data)) fclose($this->data); + } +} \ No newline at end of file