mirror of https://github.com/nodejs/node.git
src: avoid leaking snapshot fp on error
Call fclose() on the snapshot file regardless of whether reading the snapshot data succeeded. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
1e9ca451c1
commit
3344bb764a
|
@ -1174,14 +1174,15 @@ ExitCode LoadSnapshotDataAndRun(const SnapshotData** snapshot_data_ptr,
|
|||
return exit_code;
|
||||
}
|
||||
std::unique_ptr<SnapshotData> read_data = std::make_unique<SnapshotData>();
|
||||
if (!SnapshotData::FromBlob(read_data.get(), fp)) {
|
||||
bool ok = SnapshotData::FromBlob(read_data.get(), fp);
|
||||
fclose(fp);
|
||||
if (!ok) {
|
||||
// If we fail to read the customized snapshot, simply exit with 1.
|
||||
// TODO(joyeecheung): should be kStartupSnapshotFailure.
|
||||
exit_code = ExitCode::kGenericUserError;
|
||||
return exit_code;
|
||||
}
|
||||
*snapshot_data_ptr = read_data.release();
|
||||
fclose(fp);
|
||||
} else if (per_process::cli_options->node_snapshot) {
|
||||
// If --snapshot-blob is not specified, we are reading the embedded
|
||||
// snapshot, but we will skip it if --no-node-snapshot is specified.
|
||||
|
|
Loading…
Reference in New Issue