Skip to content

Commit

Permalink
feat(goffi): freeing memory after fetching result of function
Browse files Browse the repository at this point in the history
  • Loading branch information
razshare committed Mar 4, 2024
1 parent b7344a6 commit f6f63c7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib/Core/GoffiContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,14 @@ private static function loadContract(FFI $lib, string $interface) {
$resolvedArgs[] = $value;
}
$result = $lib->$methodName(...$resolvedArgs);
return match ($returnTypeName) {
'string' => FFI::string($result),
default => $result,
};

if ('string' === $returnTypeName) {
$converted = FFI::string($result);
FFI::free($result);
return $converted;
}

return $result;
};
}
return $methods;
Expand Down

0 comments on commit f6f63c7

Please sign in to comment.