Skip to content

Commit

Permalink
fix: boot resource leakage
Browse files Browse the repository at this point in the history
Introduced in #1137
  • Loading branch information
leon0399 committed Sep 29, 2024
1 parent 9aea4d8 commit d2881dd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Boot/src/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,27 @@ public function loadData(string $section, string &$filename = null): mixed

try {
$fp = \fopen($filename, 'r');
if ($fp === false) {
return null;
}

if (!\flock($fp, \LOCK_SH | \LOCK_NB)) {
\fclose($fp);
return null;
}

$data = include($filename);

\flock($fp, \LOCK_UN);
\fclose($fp);
return $data;
} catch (\Throwable) {
return null;
} finally {
if (isset($fp)) {
\fclose($fp);
}
}

return $data;
}

public function saveData(string $section, mixed $data): void
Expand Down

0 comments on commit d2881dd

Please sign in to comment.