Skip to content

Commit aeb3c2e

Browse files
authored
Merge pull request #1875 from goblint/conf-fd-leak
Fix file descriptor leak in `GobConfig.merge_file`
2 parents 53d3388 + 2c0aafc commit aeb3c2e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

.semgrep/batio.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rules:
2+
- id: batio-to_input_channel
3+
pattern: BatIO.to_input_channel
4+
message: don't use (leaks two file descriptors)
5+
languages: [ocaml]
6+
severity: ERROR

src/config/gobConfig.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,14 @@ struct
415415
in
416416
match file with
417417
| Some fn ->
418-
let v = Yojson.Safe.from_channel % BatIO.to_input_channel |> File.with_file_in (Fpath.to_string fn) in
418+
let v =
419+
let ic = Stdlib.open_in (Fpath.to_string fn) in
420+
Fun.protect ~finally:(fun () ->
421+
Stdlib.close_in ic
422+
) (fun () ->
423+
Yojson.Safe.from_channel ic
424+
)
425+
in
419426
merge v;
420427
if Goblint_tracing.tracing then Goblint_tracing.trace "conf" "Merging with '%a', resulting\n%a." GobFpath.pretty fn GobYojson.pretty !json_conf
421428
| None -> raise (Sys_error (Printf.sprintf "%s: No such file or directory" (Fpath.to_string fn)))

0 commit comments

Comments
 (0)