Data-PubSub-Shared
view release on metacpan or search on metacpan
xt/poll_cb_destroy_during_call.t view on Meta::CPAN
#
# After every callback return poll_cb must REEXTRACT_SUB and croak
# "... object destroyed during the call" / "... object was replaced during
# the call" instead of dereferencing the freed pointer. Without the guard
# the next loop iteration reads/writes freed heap: it either segfaults
# (caught as a signal below) or, if the freed memory is still mapped,
# silently runs on through it and poll_cb returns normally (exit 7 below).
# Both are failures; only the specific croak is a pass.
#
# Each child publishes 3 messages and destroys/replaces on the FIRST
# callback, so the defect window (second and later loop iterations) is
# always exercised. alarm is a backstop against a garbage-cursor spin in
# the unfixed code.
my @cases;
for my $variant (qw(Int Str Int32 Int16)) {
push @cases, ["Data::PubSub::Shared::${variant}::Sub (destroy in callback)" => sub {
my $ps = "Data::PubSub::Shared::$variant"->new(undef, 32);
$ps->publish($variant eq 'Str' ? "msg$_" : $_) for 1..3;
my $sub = $ps->subscribe_all;
( run in 2.036 seconds using v1.01-cache-2.11-cpan-4ab04211f4c )