i’m using ef (electric fence) to show the memory corruption in this script.
to cause it corrupt memory use
CORRUPT=true ef ruby bug.rb
file: bug.rb
require 'sync'
class A
def initialize
extend Sync_m
@observers = []
end
def meth
synchronize(:EX){
@observers.each do |o|
if ENV['CORRUPT']
o.notify nil
else
o.notify
end
end
}
end
def add_observer o
synchronize(:EX){
@observers << o
}
end
end
class B
def initialize a
@a = a
@a.add_observer self
end
def notify *a
Thread.new{ @a.meth }
end
end
a = A.new
b = B.new a
a.meth
STDIN.gets
note that it is the simple passing, or not, of arguments to the notify method
which triggers the bug. perhaps this will yield some hints.
regards.
-a
bug.rb (547 Bytes)
···
–
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama