Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Fix memory leak in JOIN queries #28220

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions src/Illuminate/Database/Query/JoinClause.php
Original file line number Diff line number Diff line change
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);
}
}