Fix double free of toplevel bytecode (#9855)

master
Stephen Dolan 2020-08-25 15:22:46 +01:00 committed by GitHub
parent 7bbf612a9d
commit 6e84a11181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 9 deletions

View File

@ -387,6 +387,9 @@ Working version
- #9753: fix build for Android
(Github user @EduardoRFS, review by Xavier Leroy)
- #9848, #9855: Fix double free of bytecode in toplevel
(Stephen Dolan, report by Sampsa Kiiskinen, review by Gabriel Scherer)
OCaml 4.11
----------

View File

@ -8,5 +8,7 @@ val g : unit -> int = <fun>
Exception: Not_found.
Raised at f in file "//toplevel//", line 2, characters 11-26
Called from g in file "//toplevel//", line 1, characters 11-15
Called from Toploop.load_lambda in file "toplevel/toploop.ml", line 212, characters 17-27
Called from Stdlib__fun.protect in file "fun.ml", line 33, characters 8-15
Re-raised at Stdlib__fun.protect in file "fun.ml", line 38, characters 6-52
Called from Toploop.load_lambda in file "toplevel/toploop.ml", line 212, characters 4-150

View File

@ -207,15 +207,15 @@ let load_lambda ppf lam =
Symtable.update_global_table();
let initial_bindings = !toplevel_value_bindings in
let bytecode, closure = Meta.reify_bytecode code [| events |] None in
try
match
may_trace := true;
let retval = closure () in
may_trace := false;
if can_free then Meta.release_bytecode bytecode;
Result retval
with x ->
may_trace := false;
if can_free then Meta.release_bytecode bytecode;
Fun.protect
~finally:(fun () -> may_trace := false;
if can_free then Meta.release_bytecode bytecode)
closure
with
| retval -> Result retval
| exception x ->
record_backtrace ();
toplevel_value_bindings := initial_bindings; (* PR#6211 *)
Symtable.restore_state initial_symtable;