Skip to content

Commit

Permalink
Fixes memory leak on anonymous migrations (#46073)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Feb 10, 2023
1 parent e92cbda commit ebb46b8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class Migrator
*/
protected $paths = [];

/**
* The paths that have already been required.
*
* @var array<string, \Illuminate\Database\Migrations\Migration|null>
*/
protected static $pathsAlreadyRequired = [];

/**
* The output interface implementation.
*
Expand Down Expand Up @@ -511,9 +518,13 @@ protected function resolvePath(string $path)
return new $class;
}

$migration = $this->files->getRequire($path);
$migration = static::$pathsAlreadyRequired[$path] ??= $this->files->getRequire($path);

return is_object($migration) ? $migration : new $class;
if (is_object($migration)) {
return clone $migration;
}

return new $class;
}

/**
Expand Down

0 comments on commit ebb46b8

Please sign in to comment.