Skip to content

Commit 483cd19

Browse files
tniessendanielleadams
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 <[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]>
1 parent bc9a577 commit 483cd19

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
@@ -1154,13 +1154,14 @@ int LoadSnapshotDataAndRun(const SnapshotData** snapshot_data_ptr,
11541154
return exit_code;
11551155
}
11561156
std::unique_ptr<SnapshotData> read_data = std::make_unique<SnapshotData>();
1157-
if (!SnapshotData::FromBlob(read_data.get(), fp)) {
1157+
bool ok = SnapshotData::FromBlob(read_data.get(), fp);
1158+
fclose(fp);
1159+
if (!ok) {
11581160
// If we fail to read the customized snapshot, simply exit with 1.
11591161
exit_code = 1;
11601162
return exit_code;
11611163
}
11621164
*snapshot_data_ptr = read_data.release();
1163-
fclose(fp);
11641165
} else if (per_process::cli_options->node_snapshot) {
11651166
// If --snapshot-blob is not specified, we are reading the embedded
11661167
// snapshot, but we will skip it if --no-node-snapshot is specified.

0 commit comments

Comments
 (0)