[test/ffi] Free pointer allocated via malloc

Closes: https://github.com/dart-lang/sdk/issues/50705
Change-Id: I96d0bdf5e7fe95b8841d9c7ba3db8e785574222e
Cq-Include-Trybots: luci.dart.try:vm-kernel-asan-linux-release-x64-try,vm-kernel-precomp-asan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275260
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Daco Harkes 2022-12-13 16:41:47 +00:00 committed by Commit Queue
parent fd6fa010ec
commit c3fce2f559
2 changed files with 18 additions and 6 deletions

View file

@ -8,12 +8,18 @@ import 'ffi_test_helpers.dart';
main() {
// Ensure we have FfiTrampolineData in heap.
final foo = DynamicLibrary.process()
final malloc = DynamicLibrary.process()
.lookup<NativeFunction<Pointer<Void> Function(IntPtr)>>("malloc")
.asFunction<Pointer<Void> Function(int)>();
print(foo);
print(malloc);
triggerGc();
print(foo(100).address);
final pointer = malloc(100);
print(pointer.address);
final free = DynamicLibrary.process()
.lookupFunction<Void Function(Pointer), void Function(Pointer)>('free');
free(pointer);
}

View file

@ -10,12 +10,18 @@ import 'ffi_test_helpers.dart';
main() {
// Ensure we have FfiTrampolineData in heap.
final foo = DynamicLibrary.process()
final malloc = DynamicLibrary.process()
.lookup<NativeFunction<Pointer<Void> Function(IntPtr)>>("malloc")
.asFunction<Pointer<Void> Function(int)>();
print(foo);
print(malloc);
triggerGc();
print(foo(100).address);
final pointer = malloc(100);
print(pointer.address);
final free = DynamicLibrary.process()
.lookupFunction<Void Function(Pointer), void Function(Pointer)>('free');
free(pointer);
}