Skip to content

Commit ebb46b8

Browse files
authored
Fixes memory leak on anonymous migrations (#46073)
1 parent e92cbda commit ebb46b8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class Migrator
6666
*/
6767
protected $paths = [];
6868

69+
/**
70+
* The paths that have already been required.
71+
*
72+
* @var array<string, \Illuminate\Database\Migrations\Migration|null>
73+
*/
74+
protected static $pathsAlreadyRequired = [];
75+
6976
/**
7077
* The output interface implementation.
7178
*
@@ -511,9 +518,13 @@ protected function resolvePath(string $path)
511518
return new $class;
512519
}
513520

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

516-
return is_object($migration) ? $migration : new $class;
523+
if (is_object($migration)) {
524+
return clone $migration;
525+
}
526+
527+
return new $class;
517528
}
518529

519530
/**

0 commit comments

Comments
 (0)