From 0727b9598f10904daf90807fbc1f5253dc68d6ab Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Fri, 10 Apr 2020 17:07:29 +0200 Subject: [PATCH] Remove file_id from the cloned object before destruction This prevents the cloned object from removing temporary files owned by the original object during cleanup, potentially leaving some that were created during the transaction, but these should be cleaned with the original object Fixes #205 --- tcpdf.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tcpdf.php b/tcpdf.php index 8b7d812..8f5c1f1 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -7774,7 +7774,7 @@ class TCPDF { if (isset(self::$cleaned_ids[$this->file_id])) { $destroyall = false; } - if ($destroyall AND !$preserve_objcopy) { + if ($destroyall AND !$preserve_objcopy && isset($this->file_id)) { self::$cleaned_ids[$this->file_id] = true; // remove all temporary files if ($handle = @opendir(K_PATH_CACHE)) { @@ -21717,6 +21717,8 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: public function commitTransaction() { if (isset($this->objcopy)) { $this->objcopy->_destroy(true, true); + /* The unique file_id should not be used during cleanup again */ + $this->objcopy->file_id = NULL; unset($this->objcopy); } } @@ -21730,14 +21732,22 @@ Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: */ public function rollbackTransaction($self=false) { if (isset($this->objcopy)) { + $objcopy = $this->objcopy; $this->_destroy(true, true); if ($self) { - $objvars = get_object_vars($this->objcopy); + $objvars = get_object_vars($objcopy); foreach ($objvars as $key => $value) { $this->$key = $value; } + $objcopy->_destroy(true, true); + /* The unique file_id should not be used during cleanup again */ + $objcopy->file_id = NULL; + unset($objcopy); + return $this; } - return $this->objcopy; + /* The unique file_id should not be used during cleanup again */ + $this->file_id = NULL; + return $objcopy; } return $this; }