From ed7a05116e93f7af4e273b0b8c0a4012c24657a6 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Mon, 15 Apr 2019 13:05:08 +0200 Subject: [PATCH] Fix memory leak in JOIN queries --- src/Illuminate/Database/Query/JoinClause.php | 50 +++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Database/Query/JoinClause.php b/src/Illuminate/Database/Query/JoinClause.php index 267854e74df2..e09cf2008b6f 100755 --- a/src/Illuminate/Database/Query/JoinClause.php +++ b/src/Illuminate/Database/Query/JoinClause.php @@ -21,11 +21,32 @@ class JoinClause extends Builder public $table; /** - * The parent query builder instance. + * The connection of the parent query builder. * - * @var \Illuminate\Database\Query\Builder + * @var \Illuminate\Database\ConnectionInterface */ - private $parentQuery; + protected $parentConnection; + + /** + * The grammar of the parent query builder. + * + * @var \Illuminate\Database\Query\Grammars\Grammar + */ + protected $parentGrammar; + + /** + * The processor of the parent query builder. + * + * @var \Illuminate\Database\Query\Processors\Processor + */ + protected $parentProcessor; + + /** + * The class name of the parent query builder. + * + * @var string + */ + protected $parentClass; /** * Create a new join clause instance. @@ -39,10 +60,13 @@ public function __construct(Builder $parentQuery, $type, $table) { $this->type = $type; $this->table = $table; - $this->parentQuery = $parentQuery; + $this->parentConnection = $parentQuery->getConnection(); + $this->parentGrammar = $parentQuery->getGrammar(); + $this->parentProcessor = $parentQuery->getProcessor(); + $this->parentClass = get_class($parentQuery); parent::__construct( - $parentQuery->getConnection(), $parentQuery->getGrammar(), $parentQuery->getProcessor() + $this->parentConnection, $this->parentGrammar, $this->parentProcessor ); } @@ -95,7 +119,7 @@ public function orOn($first, $operator = null, $second = null) */ public function newQuery() { - return new static($this->parentQuery, $this->type, $this->table); + return new static($this->newParentQuery(), $this->type, $this->table); } /** @@ -105,6 +129,18 @@ public function newQuery() */ protected function forSubQuery() { - return $this->parentQuery->newQuery(); + return $this->newParentQuery()->newQuery(); + } + + /** + * Create a new parent query instance. + * + * @return \Illuminate\Database\Query\Builder + */ + protected function newParentQuery() + { + $class = $this->parentClass; + + return new $class($this->parentConnection, $this->parentGrammar, $this->parentProcessor); } }