Skip to content

Commit 1e7544c

Browse files
[VarExporter] Fix possible memory-leak when using lazy-objects
1 parent 6228b11 commit 1e7544c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Caster/SymfonyCaster.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Uid\Ulid;
1616
use Symfony\Component\Uid\Uuid;
1717
use Symfony\Component\VarDumper\Cloner\Stub;
18+
use Symfony\Component\VarExporter\Internal\LazyObjectState;
1819

1920
/**
2021
* @final
@@ -67,6 +68,22 @@ public static function castHttpClientResponse($response, array $a, Stub $stub, b
6768
return $a;
6869
}
6970

71+
public static function castLazyObjectState($state, array $a, Stub $stub, bool $isNested)
72+
{
73+
if (!$isNested) {
74+
return $a;
75+
}
76+
77+
$stub->cut += \count($a) - 1;
78+
79+
return ['status' => new ConstStub(match ($a['status']) {
80+
LazyObjectState::STATUS_INITIALIZED_FULL => 'INITIALIZED_FULL',
81+
LazyObjectState::STATUS_INITIALIZED_PARTIAL => 'INITIALIZED_PARTIAL',
82+
LazyObjectState::STATUS_UNINITIALIZED_FULL => 'UNINITIALIZED_FULL',
83+
LazyObjectState::STATUS_UNINITIALIZED_PARTIAL => 'UNINITIALIZED_PARTIAL',
84+
}, $a['status'])];
85+
}
86+
7087
public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested)
7188
{
7289
$a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58();

Cloner/AbstractCloner.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ abstract class AbstractCloner implements ClonerInterface
8989
'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'],
9090
'Symfony\Component\Uid\Ulid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUlid'],
9191
'Symfony\Component\Uid\Uuid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUuid'],
92+
'Symfony\Component\VarExporter\Internal\LazyObjectState' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castLazyObjectState'],
9293
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
9394
'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
9495
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],

0 commit comments

Comments
 (0)