Skip to content

Commit 3c5db8f

Browse files
tniessenMylesBorins
authored andcommitted
src: avoid leaking snapshot fp on error
Call fclose() on the snapshot file regardless of whether reading the snapshot data succeeded. PR-URL: #46497 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 1a808a4 commit 3c5db8f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/node.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,15 @@ ExitCode LoadSnapshotDataAndRun(const SnapshotData** snapshot_data_ptr,
11681168
return exit_code;
11691169
}
11701170
std::unique_ptr<SnapshotData> read_data = std::make_unique<SnapshotData>();
1171-
if (!SnapshotData::FromBlob(read_data.get(), fp)) {
1171+
bool ok = SnapshotData::FromBlob(read_data.get(), fp);
1172+
fclose(fp);
1173+
if (!ok) {
11721174
// If we fail to read the customized snapshot, simply exit with 1.
11731175
// TODO(joyeecheung): should be kStartupSnapshotFailure.
11741176
exit_code = ExitCode::kGenericUserError;
11751177
return exit_code;
11761178
}
11771179
*snapshot_data_ptr = read_data.release();
1178-
fclose(fp);
11791180
} else if (per_process::cli_options->node_snapshot) {
11801181
// If --snapshot-blob is not specified, we are reading the embedded
11811182
// snapshot, but we will skip it if --no-node-snapshot is specified.

0 commit comments

Comments
 (0)