Skip to content

Commit

Permalink
Merge pull request #28220 from staudenmeir/join
Browse files Browse the repository at this point in the history
[5.8] Fix memory leak in JOIN queries
  • Loading branch information
taylorotwell committed Apr 15, 2019
2 parents b4343fc + ed7a051 commit eb9ea35
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions src/Illuminate/Database/Query/JoinClause.php
Expand Up @@ -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.
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}

0 comments on commit eb9ea35

Please sign in to comment.