dart-sdk/tests/ffi_2/regress_b_261224444_test.dart
Daco Harkes c3fce2f559 [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>
2022-12-13 16:41:47 +00:00

28 lines
735 B
Dart

// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.9
import 'dart:ffi';
import 'ffi_test_helpers.dart';
main() {
// Ensure we have FfiTrampolineData in heap.
final malloc = DynamicLibrary.process()
.lookup<NativeFunction<Pointer<Void> Function(IntPtr)>>("malloc")
.asFunction<Pointer<Void> Function(int)>();
print(malloc);
triggerGc();
final pointer = malloc(100);
print(pointer.address);
final free = DynamicLibrary.process()
.lookupFunction<Void Function(Pointer), void Function(Pointer)>('free');
free(pointer);
}