Skip to content

Commit

Permalink
src: avoid leaking snapshot fp on error
Browse files Browse the repository at this point in the history
Call fclose() on the snapshot file regardless of whether reading the
snapshot data succeeded.

PR-URL: #46497
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
tniessen authored and danielleadams committed Apr 3, 2023
1 parent bc9a577 commit 483cd19
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,14 @@ int 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.
exit_code = 1;
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.
Expand Down

0 comments on commit 483cd19

Please sign in to comment.