Skip to content

Commit

Permalink
Fix memory leak in FfiConverterString
Browse files Browse the repository at this point in the history
Credits to @dignifiedquire

Signed-off-by: Kristupas Antanavicius <[email protected]>
  • Loading branch information
arg0d committed Sep 22, 2023
1 parent 95b8d9d commit 3cb2fbb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bindgen/templates/StringHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type {{ ffi_converter_name }} struct{}
var {{ ffi_converter_name }}INSTANCE = {{ ffi_converter_name }}{}

func ({{ ffi_converter_name }}) lift(cRustBuf C.RustBuffer) string {
reader := fromCRustBuffer(cRustBuf).asReader()
rustBuf := fromCRustBuffer(cRustBuf)
defer rustBuf.free()

reader := rustBuf.asReader()
b, err := io.ReadAll(reader)
if err != nil {
panic(fmt.Errorf("reading reader: %w", err))
Expand Down

0 comments on commit 3cb2fbb

Please sign in to comment.