summaryrefslogtreecommitdiff
path: root/test/fiddle/test_pointer.rb
diff options
context:
space:
mode:
authorChris Seaton <chris@chrisseaton.com>2020-05-19 00:12:47 +0100
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-05-23 14:34:07 +0900
commit3015a7aae7ddc9b63149df34b1f12366e07a9563 (patch)
treed8717bceae57a47f2257f8701c02423d51dab62f /test/fiddle/test_pointer.rb
parent24b615e82ee327a9ac583937de746ba12dde2d6a (diff)
[ruby/fiddle] Improve documentation on how to correctly free memory and free memory in tests (#33)
https://github.com/ruby/fiddle/commit/e59cfd708a
Diffstat (limited to 'test/fiddle/test_pointer.rb')
-rw-r--r--test/fiddle/test_pointer.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/test/fiddle/test_pointer.rb b/test/fiddle/test_pointer.rb
index 5581c1dea7..c69e4f7142 100644
--- a/test/fiddle/test_pointer.rb
+++ b/test/fiddle/test_pointer.rb
@@ -84,7 +84,7 @@ module Fiddle
end
def test_to_ptr_io
- buf = Pointer.malloc(10)
+ buf = Pointer.malloc(10, Fiddle::RUBY_FREE)
File.open(__FILE__, 'r') do |f|
ptr = Pointer.to_ptr f
fread = Function.new(@libc['fread'],
@@ -145,7 +145,11 @@ module Fiddle
def test_free
ptr = Pointer.malloc(4)
- assert_nil ptr.free
+ begin
+ assert_nil ptr.free
+ ensure
+ Fiddle.free ptr
+ end
end
def test_free=
@@ -173,15 +177,21 @@ module Fiddle
def test_size
ptr = Pointer.malloc(4)
- assert_equal 4, ptr.size
- Fiddle.free ptr.to_i
+ begin
+ assert_equal 4, ptr.size
+ ensure
+ Fiddle.free ptr
+ end
end
def test_size=
ptr = Pointer.malloc(4)
- ptr.size = 10
- assert_equal 10, ptr.size
- Fiddle.free ptr.to_i
+ begin
+ ptr.size = 10
+ assert_equal 10, ptr.size
+ ensure
+ Fiddle.free ptr
+ end
end
def test_aref_aset