Skip to content

Commit a84783d

Browse files
author
Yorick Peterse
committedDec 26, 2015
Moved autorelease methods to FFI::Pointer
This allows code to alter the autorelease behaviour of regular Rubinius::FFI::Pointer instances. As an example, rubysl-socket returns a bunch of ifaddr pointers which are freed using freeifaddrs(). By default these pointers have auto-releasing enabled which results in Rubinius attempting to finalize/free already free'd pointers which in turn segfaults Rubinius.
1 parent dfa4f06 commit a84783d

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed
 

‎kernel/platform/pointer.rb

+15-16
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,21 @@ def primitive_write_pointer(obj)
253253
raise PrimitiveFailure, "FFI::Pointer#primitive_write_pointer primitive failed"
254254
end
255255

256+
##
257+
# If +val+ is true, this Pointer object will call
258+
# free() on it's address when it is garbage collected.
259+
def autorelease=(val)
260+
Rubinius.primitive :pointer_set_autorelease
261+
raise PrimitiveFailure, "FFI::Pointer#autorelease= primitive failed"
262+
end
263+
264+
##
265+
# Returns true if autorelease is enabled, otherwise false.
266+
def autorelease?
267+
Rubinius.primitive :pointer_autorelease_p
268+
raise PrimitiveFailure, "FFI::Pointer#pointer_autorelease_p primitive failed"
269+
end
270+
256271
NULL = Pointer.new(0x0)
257272
end
258273

@@ -370,22 +385,6 @@ def free
370385
Rubinius.primitive :pointer_free
371386
raise PrimitiveFailure, "FFI::MemoryPointer#free primitive failed"
372387
end
373-
374-
##
375-
# If +val+ is true, this MemoryPointer object will call
376-
# free() on it's address when it is garbage collected.
377-
def autorelease=(val)
378-
Rubinius.primitive :pointer_set_autorelease
379-
raise PrimitiveFailure, "FFI::MemoryPointer#autorelease= primitive failed"
380-
end
381-
382-
##
383-
# Returns true if autorelease is enabled, otherwise false.
384-
def autorelease?
385-
Rubinius.primitive :pointer_autorelease_p
386-
raise PrimitiveFailure, "FFI::MemoryPointer#pointer_autorelease_p primitive failed"
387-
end
388-
389388
end
390389

391390
class DynamicLibrary::Symbol < Pointer

0 commit comments

Comments
 (0)
Please sign in to comment.