CC: | Bulldog <bulldogorama [...] gmail.com> |
Subject: | Initialization failure with init_arg (possible race condition) |
Date: | Tue, 13 Apr 2010 11:55:58 -0700 |
To: | bug-Class-Std [...] rt.cpan.org |
From: | Bulldog <bulldogorama [...] gmail.com> |
The INITIALIZATION loop can fail to initialize properly using 'init_arg'.
Using a base class that has an :init_arg <events> and several subclasses.
Created an instance of <subclass_1> scoped to an 'if' block.
In a separate 'if' block immediately following, created an instance of a
different subclass, <subclass_2>.
The instance of <subclass2> had the same 'events' attribute as the former
instance of <subclass1>, even though the 'events' argument passed to the
constructor was correct.
Naturally, this caused the instance of <subclass2> to behave incorrectly.
Inspection revealed that both instances had the same 'ident'.
I believe the issue is in
http://cpansearch.perl.org/src/DCONWAY/Class-Std-0.011/lib/Class/Std.pm on
line 446:
444 INITIALIZATION:
445 for my $attr_ref ( @{$attribute{$base_class}} ) {
446 next INITIALIZATION if defined $attr_ref->{ref}{$new_obj_id};
447
448 # Get arg from initializer list...
If there is a race condition between when DESTROY gets called (clearing the
attribute for the previous instance) and when the initialization code is
run, then I believe the condition for line 446 will be true and the old
attribute will be preserved, corrupting the new object.
Thanks.
- David Guy