Subject: | Heap::Fibonacci::elem_DESTROY causes error during garbage collection |
The elem_DESTROY sub (used during garbage collection) is subtly broken:
sub elem_DESTROY {
...
while( $el ) {
$ch = $el->{child} and elem_DESTROY $ch;
$next = $el->{right};
$el->{val}->heap(undef);
$el->{child} = $el->{right} = $el->{left} = $el->{p} = $el->{val}
= undef;
$el = $next;
}
}
The loop keeps walking to the right sibling around the fibonacci ring, and clearing destroying the children as well as clearing the heap reference, the data and the left and right references.
However it will eventually reach the end of the ring and encounter itself again - and at this point the {val} will be undef and the call to $el->{val}->heap(undef) will fail.
It probably should set $next conditionally, as in:
$next = ($el->{right} != $el)? $el->{right} : undef;
cheers,
chris