in reply to Mark-and-sweep-like mechanism to verify refcount integrity

It really depends. On perl5.6.x (and probably earlier), this will cause Attempt to free unreferenced scalar at - line 2.
@a = (bless {}, 'X'); sub X::DESTROY { @a = () } @a=(); __END__
Whats important to note is that the warning comes with a line number, which you can use to investigate (it should give away which variable caused it). If XS is to blame, it should be possible check wether SvREFCNT_dec() was called too many times, or that SvREFCNT_inc() was called too few times, or that the SV was mortalized when it shouldn't have been, or that memory has been corrupted.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^2: Mark-and-sweep-like mechanism to verify refcount integrity
by nobull (Friar) on Oct 05, 2004 at 09:28 UTC
    Whats important to note is that the warning comes with a line number, which you can use to investigate (it should give away which variable caused it)

    As I said in my orginal post I suspect there is action-at-a-distance going on. The real culprit is in one place but the bug is manifesting with respect to another variable that's getting accidently aliased.

    When I run the code (which is in a module) in a standalone CGI script it doesn't give warnings. When I run the code under Apache::Registry then it starts giving warnings in many unrealated places after a few transactions.

    Here is an example of one of the places where it's giving a warning.

    for my $field ( @$self{@{$_{FIELDS}}} ) { $field->set_related(AFTER => \@keys ); $field->{MULTI} = 1 if $_{MULTICODE} && ! exists $field->{MUL +TI}; $field->{ORDERED} = 1 if $_{ORDER} && ! exists $field->{ORDERE +D}; $field->{CONTEXT_KEYS} = $_{CONTEXT_KEYS} if $_{CONTEXT_KEYS} +&& ! exists $field->{CONTEXT_KEYS}; if ( $table ) { $field->{TABLE} = $table unless exists $field->{TABLE}; $field->{COLUMN} = $fieldmap->{$field} || "$field" unless exists $field->{COLUMN}; } } if ( $structured_field ) { # Warning here! $fieldmap = {%$fieldmap}; my @pseudo_fields = map { @$_ } values %$structured_field; @$fieldmap{@pseudo_fields} = map { [ $fieldmap->{$_} || $_ ] } + @pseudo_fields; }

    As you see the line where the warning appears has no buisness unreferencing any scalars. The variable  $structured_field is, by the way, undef.

    The perhaps interesting thing is that the variables $self and $field are not a blessed hashes but rather are objects that overload '%{}'. Furthermore the '%{}' overload on $self is done via a transitory tied hash...

    use overload '%{}' => sub { my $self = shift; tie my(%h), $self; \%h }; sub TIEHASH { shift }

    UPDATE Replacing the transitory tied hash with a persistant one did not fix the problem.