Skip to content

Commit

Permalink
[sqlite] clear bindings after execution
Browse files Browse the repository at this point in the history
Summary:
The OCaml bindings to SQLite ensure that when a value is bound to a query parameter it is copied to a value that is memory-managed by SQLite. This means that any value bound occupies memory until the bindings are cleared, and this memory lies outside of the OCaml heap. When writing out summaries, this memory can potentially amount to a lot.

This diff clears bindings and resets the prepared statement right after query execution, meaning that memory for parameter values is released immediately.

Reviewed By: dulmarod

Differential Revision:
D50126133

Privacy Context Container: L1208441

fbshipit-source-id: ea7e9dfb2272ca78a4db935ef9a277571663d112
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Oct 12, 2023
1 parent 646f832 commit 1d5855a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions infer/src/base/Database.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ let register_statement id =
| None ->
L.(die InternalError) "database not initialized"
| Some (stmt, db) ->
Sqlite3.reset stmt |> SqliteUtils.check_result_code db ~log:"reset prepared statement" ;
Sqlite3.clear_bindings stmt
|> SqliteUtils.check_result_code db ~log:"clear bindings of prepared statement" ;
(stmt, db)
in
fun stmt_fmt -> Printf.ksprintf k stmt_fmt
Expand All @@ -238,6 +235,9 @@ let with_registered_statement get_stmt ~f =
PerfEvent.(log (fun logger -> log_begin_event logger ~name:"sql op" ())) ;
let stmt, db = get_stmt () in
let result = f db stmt in
Sqlite3.reset stmt |> SqliteUtils.check_result_code db ~log:"reset prepared statement" ;
Sqlite3.clear_bindings stmt
|> SqliteUtils.check_result_code db ~log:"clear bindings of prepared statement" ;
PerfEvent.(log (fun logger -> log_end_event logger ())) ;
result

Expand Down

0 comments on commit 1d5855a

Please sign in to comment.