Skip to content

Commit fe815ce

Browse files
committed
undo use Fun.protect, closes objects too early
1 parent 3227bae commit fe815ce

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/ocaml_libbpf.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ let with_bpf_object_open_load_link ~obj_path ~program_names
8181
failwith_f "Failed to find %s programs" (String.concat "," not_found));
8282

8383
(* Run before_link user initialization code *)
84-
Fun.protect
85-
~finally:(fun () -> bpf_object_close obj)
86-
(fun () -> before_link obj);
84+
(try before_link obj
85+
with e ->
86+
bpf_object_close obj;
87+
raise e);
8788

8889
(* Get list of links *)
8990
let links, not_attached =
@@ -98,9 +99,13 @@ let with_bpf_object_open_load_link ~obj_path ~program_names
9899
(* Detached successfully attached before shutdown *)
99100
cleanup ~links obj;
100101
failwith_f "Failed to link %s programs" (String.concat "," not_attached));
102+
Printf.printf "IM HERE\n%!";
101103

102104
(* Run user program *)
103-
Fun.protect ~finally:(fun () -> cleanup ~links obj) (fun () -> fn obj links);
105+
(try fn obj links
106+
with e ->
107+
cleanup ~links obj;
108+
raise e);
104109

105110
(* Ensure proper shutdown *)
106111
cleanup ~links obj

0 commit comments

Comments
 (0)