Skip to content

Commit

Permalink
fix: fix memory leak with local evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori committed Jun 25, 2024
1 parent 83aeb87 commit c702c7e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/experiment/local/evaluation/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Kotlin < FFI::Struct

class Libevaluation_interop_ExportedSymbols < FFI::Struct
layout :DisposeStablePointer, callback([:pointer], :void),
:DisposeString, callback([:string], :void),
:DisposeString, callback([:pointer], :void),
:IsInstance, callback([:pointer, :string], :pointer),
:createNullableByte, callback([:string], :pointer),
:getNonNullValueOfByte, callback([:pointer], :pointer),
Expand Down Expand Up @@ -59,9 +59,13 @@ class Libevaluation_interop_ExportedSymbols < FFI::Struct

def evaluation(rule_json, user_json)
lib = EvaluationInterop.libevaluation_interop_symbols()
fn = lib[:kotlin][:root][:evaluate]
result_json = fn.call(rule_json, user_json).read_string
evaluate = lib[:kotlin][:root][:evaluate]
dispose = lib[:DisposeString]
result_raw = evaluate.call(rule_json, user_json)
result_json = result_raw.read_string
result = JSON.parse(result_json)
dispose.call(result_raw)

if result["error"] != nil
raise "#{result["error"]}"
elsif result["result"] == nil
Expand Down

0 comments on commit c702c7e

Please sign in to comment.