diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-24 20:25:40 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-24 20:39:41 -0300 |
| commit | 8dd98ab247db83c6e7a49676f562f2cf18237700 (patch) | |
| tree | 808ae1f48311f273d900022ea9d06e9b29c82dfd /lib/kernel/Path.ml | |
| parent | 6a41a413be4eaade89f5eeab29b9e933551de8a0 (diff) | |
| download | RNT-8dd98ab247db83c6e7a49676f562f2cf18237700.tar.gz RNT-8dd98ab247db83c6e7a49676f562f2cf18237700.zip | |
fix handle leak by always release a handle now from copies
Diffstat (limited to 'lib/kernel/Path.ml')
| -rw-r--r-- | lib/kernel/Path.ml | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml index 512cfb0..2a9b053 100644 --- a/lib/kernel/Path.ml +++ b/lib/kernel/Path.ml @@ -22,6 +22,10 @@ module Error = struct condition "overlapping-change" "A batch of changes both replaced an object and changed inside it" ("path" |=| Concepts.Value.String (to_string path)) + + let unheld path = + condition "path-unheld" "The object at the path could not be held" + ("path" |=| Concepts.Value.String (to_string path)) end let walking ?missing f g handle path = @@ -42,7 +46,11 @@ let walking ?missing f g handle path = | Some elem -> f x handle (fun () -> walk elem xs) ) in Handle.with_autorelease (fun () -> - walk handle path + begin match path with + | [] -> ( + match Handle.copy handle with Some copy -> g copy | None -> Error (Error.unheld path) ) + | _ -> walk handle path + end |> Result.map_error Concepts.Condition.(complement ("path" |=| Concepts.Value.String (to_string path))) ) @@ -55,8 +63,9 @@ let update handle path key reference value = let open Utilities.Result in let open Protocols in let* target = lookup handle path in - let* registry = Handle.require Registry.from target in - Registry.update registry key reference value + Handle.releasing target (fun () -> + let* registry = Handle.require Registry.from target in + Registry.update registry key reference value ) (* The changes at this object, and those beneath each child they reach. *) let split changes = |
