In perl.git, the branch sprout/misc-post-5.16 has been updated <http://perl5.git.perl.org/perl.git/commitdiff/f0eae910d6824b0506e27b59338f2cf593419c04?hp=38aa596d1f4dd263ea76273296a3241b1e155fe8>
- Log ----------------------------------------------------------------- commit f0eae910d6824b0506e27b59338f2cf593419c04 Author: Father Chrysostomos <[email protected]> Date: Tue Apr 24 16:00:36 2012 -0700 [perl #112358] Storable: Donât create RV with no refcnt Otherwise assigning to it will cause the referent to be freed, because nothing but Storable knows that it has no reference count. Storable.xs was creating a new RV without increasing the refe- rence count on the referent. It was then using it to call the STORABLE_freeze method on the object. Since Perl passes arguments by reference, it was possible to unref the reference by assigning to $_[0] within STORABLE_freeze. That would cause the objectâs reference count to go down. M dist/Storable/Storable.xs M dist/Storable/t/blessed.t commit ca3c770b653aea1ceb94da720b32662b1b958a60 Author: Father Chrysostomos <[email protected]> Date: Tue Apr 24 16:00:13 2012 -0700 Increase $Storable::VERSION to 2.35 M dist/Storable/Storable.pm ----------------------------------------------------------------------- Summary of changes: dist/Storable/Storable.pm | 2 +- dist/Storable/Storable.xs | 3 +-- dist/Storable/t/blessed.t | 11 ++++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/Storable/Storable.pm b/dist/Storable/Storable.pm index 5601f6d..6f92611 100644 --- a/dist/Storable/Storable.pm +++ b/dist/Storable/Storable.pm @@ -21,7 +21,7 @@ package Storable; @ISA = qw(Exporter); use vars qw($canonical $forgive_me $VERSION); -$VERSION = '2.34'; +$VERSION = '2.35'; BEGIN { if (eval { local $SIG{__DIE__}; require Log::Agent; 1 }) { diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs index ca6f9b4..30f9281 100644 --- a/dist/Storable/Storable.xs +++ b/dist/Storable/Storable.xs @@ -2916,9 +2916,8 @@ static int store_hook( TRACEME(("about to call STORABLE_freeze on class %s", classname)); - ref = newRV_noinc(sv); /* Temporary reference */ + ref = newRV_inc(sv); /* Temporary reference */ av = array_call(aTHX_ ref, hook, clone); /* @a = $object->STORABLE_freeze($c) */ - SvRV_set(ref, NULL); SvREFCNT_dec(ref); /* Reclaim temporary reference */ count = AvFILLp(av) + 1; diff --git a/dist/Storable/t/blessed.t b/dist/Storable/t/blessed.t index 6657e3c..6b25f37 100644 --- a/dist/Storable/t/blessed.t +++ b/dist/Storable/t/blessed.t @@ -27,7 +27,7 @@ use Storable qw(freeze thaw store retrieve); ); my $test = 12; -my $tests = $test + 22 + 2 * 6 * keys %::immortals; +my $tests = $test + 23 + 2 * 6 * keys %::immortals; plan(tests => $tests); package SHORT_NAME; @@ -249,3 +249,12 @@ is($STRESS_THE_STACK::freeze_count, 1); is($STRESS_THE_STACK::thaw_count, 1); isnt($t, undef); is(ref $t, 'STRESS_THE_STACK'); + +{ + package ModifyARG112358; + sub STORABLE_freeze { $_[0] = "foo"; } + my $o= {str=>bless {}}; + my $f= ::freeze($o); + ::is ref $o->{str}, __PACKAGE__, + 'assignment to $_[0] in STORABLE_freeze does not corrupt things'; +} -- Perl5 Master Repository
